ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-08-26 05:06:07
Exec Total Coverage
Lines: 2778 8332 33.3%
Functions: 76 290 26.2%
Branches: 2402 7193 33.4%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "zq/zquestdat.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "md5.h"
34 #include "zc/zc_custom.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern ZModule zcm;
59 extern zcmodule moduledata;
60 extern uint8_t ViewLayer3BG, ViewLayer2BG;
61 extern int32_t LayerDitherBG, LayerDitherSz;
62 extern bool NoHighlightLayer0;
63
64 using std::string;
65 using std::pair;
66 #define EPSILON 0.01 // Define your own tolerance
67 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 9 zmap Map;
80 int32_t prv_mode=0;
81 int16_t ffposx[MAXFFCS];
82 int16_t ffposy[MAXFFCS];
83 int32_t ffprvx[MAXFFCS];
84 int32_t ffprvy[MAXFFCS];
85 void init_ffpos()
86 {
87 for (word q = 0; q < MAXFFCS; ++q)
88 {
89 ffposx[q] = -1000;
90 ffposy[q] = -1000;
91 ffprvx[q] = -10000000;
92 ffprvy[q] = -10000000;
93 }
94 }
95
96 bool save_warn=true;
97
98 int32_t COMBOPOS(int32_t x, int32_t y)
99 {
100 return (((y) & 0xF0) + ((x) >> 4));
101 }
102 int32_t COMBOPOS_B(int32_t x, int32_t y)
103 {
104 if(unsigned(x) >= 256 || unsigned(y) >= 176)
105 return -1;
106 return COMBOPOS(x,y);
107 }
108 int32_t COMBOX(int32_t pos)
109 {
110 return ((pos) % 16 * 16);
111 }
112 int32_t COMBOY(int32_t pos)
113 {
114 return ((pos) & 0xF0);
115 }
116
117 void reset_dmap(int32_t index)
118 {
119 bound(index,0,MAXDMAPS-1);
120 DMaps[index].clear();
121 DMaps[index].title = "";
122 sprintf(DMaps[index].intro, " ");
123 }
124
125 void reset_dmaps()
126 {
127 for(int32_t i=0; i<MAXDMAPS; i++)
128 reset_dmap(i);
129 }
130
131 void truncate_dmap_title(std::string& title)
132 {
133 title.resize(21, ' ');
134 }
135
136 mapscr* zmap::get_prvscr()
137 {
138 return &prvscr;
139 }
140
141
7/12
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 90 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 18 times.
108 zmap::zmap()
142 {
143 18 can_paste=false;
144 18 prv_cmbcycle=0;
145 18 prv_advance=0;
146 18 prv_freeze=0;
147 18 copyffc=-1;
148
149 18 memset(scrpos, 0, sizeof(scrpos));
150 18 screens=NULL;
151 18 prv_time=0;
152 18 prv_scr=0;
153 18 prv_map=0;
154 18 copyscr=0;
155 18 currscr=0;
156 18 copymap=0;
157 18 currmap=0;
158 18 layer_target_map = 0;
159 18 layer_target_scr = 0;
160 18 layer_target_multiple = 0;
161
162 18 }
163 18 zmap::~zmap()
164 {
165 18 }
166
167 9 void zmap::clear()
168 {
169
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
170 9 }
171 void zmap::force_refr_pointer()
172 {
173 if(unsigned(currmap) > map_count || (currmap*MAPSCRS > TheMaps.size()))
174 screens = nullptr;
175 else screens = &TheMaps[currmap*MAPSCRS];
176 }
177 bool zmap::CanUndo()
178 {
179 return undo_stack.size() > 0;
180 }
181 bool zmap::CanRedo()
182 {
183 return redo_stack.size() > 0;
184 }
185 bool zmap::CanPaste()
186 {
187 return can_paste;
188 }
189 int32_t zmap::CopyScr()
190 {
191 return (copymap<<8)+copyscr;
192 }
193 int32_t zmap::getCopyFFC()
194 {
195 return copyffc;
196 }
197 set_ffc_command::data_t zmap::getCopyFFCData()
198 {
199 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
200 }
201 29 int32_t zmap::getMapCount()
202 {
203 29 return map_count;
204 }
205 int32_t zmap::getLayerTargetMap()
206 {
207 return layer_target_map;
208 }
209 int32_t zmap::getLayerTargetScr()
210 {
211 return layer_target_scr;
212 }
213 int32_t zmap::getLayerTargetMultiple()
214 {
215 return layer_target_multiple;
216 }
217 bool zmap::isDungeon(int32_t scr)
218 {
219 for(int32_t i=0; i<4; i++)
220 {
221 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
222 {
223 return false;
224 }
225 }
226
227 return true;
228 }
229
230 bool zmap::clearall(bool validate)
231 {
232 Color=0;
233 char tbuf[10];
234
235 if((header.templatepath[0]!=0)&&validate)
236 {
237 if(!valid_zqt(header.templatepath))
238 {
239 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
240 return false;
241 }
242 }
243
244 for(int32_t i=0; i<map_count; i++)
245 {
246 setCurrMap(i);
247 sprintf(tbuf, "%d", i);
248 clearmap(true);
249 }
250
251 setCurrMap(0);
252 return true;
253 }
254
255 bool zmap::reset_templates(bool validate)
256 {
257 //why are we doing this?
258 if(colordata==NULL)
259 {
260 return false;
261 }
262
263 char *deletefilename=(char *)malloc(1);
264 ASSERT(deletefilename);
265 deletefilename[0]=0;
266
267 //int32_t ret;
268 word version, build, dummy, sversion=0;
269 byte dummyc;
270 word dummyw;
271 //int32_t section_size;
272 word temp_map_count;
273 mapscr temp_mapscr;
274 PACKFILE *f=NULL;
275
276 // setPackfilePassword(datapwd);
277 f=open_quest_template(&header, deletefilename, validate);
278 get_version_and_build(f, &version, &build);
279
280 if(!find_section(f, ID_MAPS))
281 {
282 // setPackfilePassword(NULL);
283 return false;
284 }
285
286 //section version info
287 if(!p_igetw(&sversion,f))
288 {
289 return false;
290 }
291
292 if(!p_igetw(&dummy,f))
293 {
294 return false;
295 }
296
297 //section size
298 dword dummy_size;
299 if(!p_igetl(&dummy_size,f))
300 {
301 return false;
302 }
303
304 //finally... section data
305 if(!p_igetw(&temp_map_count,f))
306 {
307 return false;
308 }
309
310 if(version>12)
311 {
312 if(!p_getc(&dummyc,f))
313 return qe_invalid;
314
315 if(!p_getc(&dummyc,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_igetw(&dummyw,f))
328 return qe_invalid;
329
330 if(!p_igetw(&dummyw,f))
331 return qe_invalid;
332
333 if(!p_igetw(&dummyw,f))
334 return qe_invalid;
335
336 if(!p_igetw(&dummyw,f))
337 return qe_invalid;
338
339 if(!p_igetw(&dummyw,f))
340 return qe_invalid;
341
342 if(!p_igetw(&dummyw,f))
343 return qe_invalid;
344
345 if(!p_igetw(&dummyw,f))
346 return qe_invalid;
347
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_getc(&dummyc,f))
352 return qe_invalid;
353 }
354
355 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
356 {
357 readmapscreen(f, &header, &temp_mapscr, sversion);
358 }
359
360 readmapscreen(f, &header, &TheMaps[128], sversion);
361 readmapscreen(f, &header, &TheMaps[129], sversion);
362
363 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
364 {
365 readmapscreen(f, &header, &temp_mapscr, sversion);
366 }
367
368 if(version>12)
369 {
370 if(!p_getc(&dummyc,f))
371 return qe_invalid;
372
373 if(!p_getc(&dummyc,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_igetw(&dummyw,f))
386 return qe_invalid;
387
388 if(!p_igetw(&dummyw,f))
389 return qe_invalid;
390
391 if(!p_igetw(&dummyw,f))
392 return qe_invalid;
393
394 if(!p_igetw(&dummyw,f))
395 return qe_invalid;
396
397 if(!p_igetw(&dummyw,f))
398 return qe_invalid;
399
400 if(!p_igetw(&dummyw,f))
401 return qe_invalid;
402
403 if(!p_igetw(&dummyw,f))
404 return qe_invalid;
405
406 if(!p_getc(&dummyc,f))
407 return qe_invalid;
408
409 if(!p_getc(&dummyc,f))
410 return qe_invalid;
411 }
412
413 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
414 {
415 readmapscreen(f, &header, &temp_mapscr, sversion);
416 }
417
418 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
419 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
420
421 pack_fclose(f);
422 clear_quest_tmpfile();
423
424 if(deletefilename[0]==0)
425 {
426 delete_file(deletefilename);
427 }
428
429
430 return true;
431 }
432
433 bool zmap::clearmap(bool newquest)
434 {
435 if(currmap<map_count)
436 {
437 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
438 {
439 clearscr(i);
440 }
441
442 setCurrScr(0);
443
444 if(newquest)
445 {
446 if(!reset_templates(false))
447 {
448 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
449 }
450 }
451 }
452
453 return true;
454 }
455
456 mapscr* zmap::CurrScr()
457 {
458 return screens+currscr;
459 }
460 mapscr* zmap::Scr(int32_t scr)
461 {
462 return screens+scr;
463 }
464 mapscr* zmap::AbsoluteScr(int32_t scr)
465 {
466 if(unsigned(scr) >= MAPSCRS*getMapCount())
467 return nullptr;
468 return &TheMaps[scr];
469 }
470 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
471 {
472 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
473 return nullptr;
474 return AbsoluteScr((map*MAPSCRS)+scr);
475 }
476 void zmap::set_prvscr(int32_t map, int32_t scr)
477 {
478 prvscr=TheMaps[(map*MAPSCRS)+scr];
479
480 for(int32_t i=0; i<6; i++)
481 {
482 if(prvscr.layermap[i]>0)
483 {
484 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
485 }
486 else
487 prvlayers[i].valid = 0;
488 }
489
490 prv_map=map;
491 prv_scr=scr;
492 }
493 71 int32_t zmap::getCurrMap()
494 {
495 71 return currmap;
496 }
497 bool zmap::isDark()
498 {
499 return (screens[currscr].flags&fDARK)!=0;
500 }
501
502 void zmap::setCurrentView(int32_t map, int32_t scr)
503 {
504 bool change_view = map != Map.getCurrMap() || scr != Map.getCurrScr();
505 if (map != Map.getCurrMap()) Map.setCurrMap(map);
506 if (scr != Map.getCurrScr()) Map.setCurrScr(scr);
507 if (change_view)
508 {
509 refresh(rALL);
510 rebuild_trans_table();
511 }
512 }
513
514 9 void zmap::setCurrMap(int32_t index)
515 {
516 9 int32_t oldmap=currmap;
517 9 optional<int> oldcolor;
518
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
519 oldcolor = getcolor();
520 9 scrpos[currmap]=currscr;
521 9 currmap=bound(index,0,map_count);
522 9 screens=&TheMaps[currmap*MAPSCRS];
523
524 9 currscr=scrpos[currmap];
525 9 int newcolor = getcolor();
526 9 loadlvlpal(newcolor);
527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
528 9 rebuild_trans_table();
529
530 9 reset_combo_animations2();
531 9 mmap_mark_dirty();
532 9 }
533
534 17 int32_t zmap::getCurrScr()
535 {
536 17 return currscr;
537 }
538 9 void zmap::setCurrScr(int32_t scr)
539 {
540
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if(scr==currscr) return;
541
542 8 int32_t oldscr=currscr;
543 8 int32_t oldcolor=getcolor();
544
545
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if(!(screens[currscr].valid&mVALID))
546 {
547 2 oldcolor=-1;
548 2 }
549
550 8 currscr=bound(scr,0,MAPSCRS-1);
551 8 int32_t newcolor=getcolor();
552 8 loadlvlpal(newcolor);
553
554 //setcolor(newcolor);
555
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!(screens[currscr].valid&mVALID))
556 {
557 newcolor=-1;
558 }
559
560
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if(newcolor!=oldcolor)
561 {
562 7 rebuild_trans_table();
563 7 }
564
565 8 reset_combo_animations2();
566 8 setlayertarget();
567 8 mmap_mark_dirty();
568 9 }
569
570 8 void zmap::setlayertarget()
571 {
572 8 layer_target_map = 0;
573 8 layer_target_multiple = 0;
574
575
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
576 {
577
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
578 {
579 2856 int32_t i=(m*MAPSCRS+s);
580 2856 mapscr *ts=&TheMaps[i];
581
582 // Search through each layer
583
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
584 {
585
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==currscr && (ts->layermap[w]-1)==currmap)
586 {
587 if(layer_target_map > 0)
588 {
589 layer_target_multiple += 1;
590 continue;
591 }
592
593 layer_target_map = m+1;
594 layer_target_scr = s;
595 }
596 17136 }
597 2856 }
598 21 }
599 8 }
600
601 void zmap::setcolor(int32_t c)
602 {
603 screens[currscr].valid |= mVALID;
604 screens[currscr].color = c;
605
606 if(Color!=c)
607 {
608 Color = c;
609 loadlvlpal(c);
610 rebuild_trans_table();
611 }
612
613 mmap_mark_dirty();
614 }
615
616 25 int32_t zmap::getcolor()
617 {
618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
619 {
620 return prvscr.color;
621 }
622
623 25 return screens[currscr].color;
624 25 }
625
626 void zmap::resetflags()
627 {
628 byte *di=&(screens[currscr].valid);
629
630 for(int32_t i=1; i<48; i++)
631 {
632 *(di+i)=0;
633 }
634 }
635
636 word zmap::tcmbdat(int32_t pos)
637 {
638 return screens[TEMPLATE].data[pos];
639 }
640
641 word zmap::tcmbcset(int32_t pos)
642 {
643 return screens[TEMPLATE].cset[pos];
644 }
645
646 int32_t zmap::tcmbflag(int32_t pos)
647 {
648 return screens[TEMPLATE].sflag[pos];
649 }
650
651 word zmap::tcmbdat2(int32_t pos)
652 {
653 return screens[TEMPLATE2].data[pos];
654 }
655
656 word zmap::tcmbcset2(int32_t pos)
657 {
658 return screens[TEMPLATE2].cset[pos];
659 }
660
661 int32_t zmap::tcmbflag2(int32_t pos)
662 {
663 return screens[TEMPLATE2].sflag[pos];
664 }
665
666 void zmap::TemplateAll()
667 {
668 StartListCommand();
669 for(int32_t i=0; i<128; i++)
670 {
671 if((screens[i].valid&mVALID) && isDungeon(i))
672 DoTemplateCommand(-1, i, currscr);
673 }
674 FinishListCommand();
675 }
676
677 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
678 {
679 if(scr==TEMPLATE)
680 return;
681
682 if(!(screens[scr].valid&mVALID))
683 screens[scr].color=Color;
684
685 screens[scr].valid|=mVALID;
686
687 for(int32_t i=0; i<32; i++)
688 {
689 screens[scr].data[i]=screens[TEMPLATE].data[i];
690 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
691 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
692 }
693
694 for(int32_t i=144; i<176; i++)
695 {
696 screens[scr].data[i]=screens[TEMPLATE].data[i];
697 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
698 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
699 }
700
701 for(int32_t y=2; y<=9; y++)
702 {
703 int32_t j=y<<4;
704 screens[scr].data[j]=screens[TEMPLATE].data[j];
705 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
706 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
707 ++j;
708 screens[scr].data[j]=screens[TEMPLATE].data[j];
709 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
710 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
711 ++j;
712 j+=12;
713 screens[scr].data[j]=screens[TEMPLATE].data[j];
714 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
715 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
716 ++j;
717 screens[scr].data[j]=screens[TEMPLATE].data[j];
718 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
719
720 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
721 ++j;
722 }
723
724 if(floorcombo!=-1)
725 {
726 for(int32_t y=2; y<9; y++)
727 for(int32_t x=2; x<14; x++)
728 {
729 int32_t i=(y<<4)+x;
730 screens[scr].data[i] = floorcombo;
731 screens[scr].cset[i] = floorcset;
732 }
733 }
734
735 for(int32_t i=0; i<4; i++)
736 putdoor(scr,i,screens[scr].door[i]);
737 }
738
739
740 void zmap::clearscr(int32_t scr)
741 {
742 screens[scr].zero_memory();
743 screens[scr].valid=mVERSION;
744 for(int q = 0; q < 6; ++q)
745 {
746 auto layer = map_autolayers[currmap*6+q];
747 screens[scr].layermap[q] = layer;
748 screens[scr].layerscreen[q] = layer ? scr : 0;
749 }
750 mmap_mark_dirty();
751 }
752
753 const char *loaderror[] =
754 {
755
756 "OK","File not found","Incomplete data",
757 "Invalid version","Invalid file"
758
759 };
760
761 int32_t zmap::load(const char *path)
762 {
763 PACKFILE *f=pack_fopen_password(path,F_READ, "");
764
765 if(!f)
766 return 1;
767
768
769 int16_t version;
770 byte build;
771
772 //get the version
773 if(!p_igetw(&version,f))
774 {
775 goto file_error;
776 }
777
778 //get the build
779 if(!p_getc(&build,f))
780 {
781 goto file_error;
782 }
783
784 for(int32_t i=0; i<MAPSCRS; i++)
785 {
786 mapscr tmpimportscr;
787 tmpimportscr.zero_memory();
788 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
789 {
790 al_trace("failed zmap::load\n");
791 goto file_error;
792 }
793
794 switch(ImportMapBias)
795 {
796 case 0:
797 *(screens+i) = tmpimportscr;
798 break;
799
800 case 1:
801 if(!(screens[i].valid&mVALID))
802 {
803 *(screens+i) = tmpimportscr;
804 }
805 break;
806
807 case 2:
808 if(tmpimportscr.valid&mVALID)
809 {
810 *(screens+i) = tmpimportscr;
811 }
812 break;
813 }
814 }
815
816
817 pack_fclose(f);
818
819 setCurrScr(0);
820 mmap_mark_dirty();
821 return 0;
822
823 file_error:
824 pack_fclose(f);
825 clearmap(false);
826 return 2;
827 }
828
829 int32_t zmap::save(const char *path)
830 {
831 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
832
833 if(!f)
834 return 1;
835
836 if(!p_iputw(V_MAPS,f))
837 {
838 pack_fclose(f);
839 return 3;
840 }
841
842 // This was the "build number", but that's totally useless here. Keep this junk byte
843 // so as not to totally break exports between ZC versions.
844 if(!p_putc(0,f))
845 {
846 pack_fclose(f);
847 return 3;
848 }
849
850 for(int32_t i=0; i<MAPSCRS; i++)
851 {
852 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
853 {
854 pack_fclose(f);
855 return 2;
856 }
857 }
858
859 pack_fclose(f);
860 return 0;
861 }
862
863
864 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
865 {
866 // Hookshots can be blocked by solid combos on all 3 ground layers.
867 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
868
869 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
870 return true;
871 if (c->walk&(1<<i))
872 return false;
873
874 for(int32_t k=0; k<2; k++)
875 {
876 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
877
878 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
879 {
880 return false;
881 }
882 }
883
884 return true;
885 }
886
887 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
888 {
889 // Hookshots can be blocked by solid combos on all 3 ground layers.
890 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
891
892 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
893 return true;
894 if (c->walk&(1<<i))
895 return false;
896
897 for(int32_t k=0; k<2; k++)
898 {
899 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
900
901 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
902 {
903 return false;
904 }
905 }
906
907 return true;
908 }
909
910 bool zmap::isstepable(int32_t combo)
911 {
912 // This is kind of odd but it's true to the engine (see maps.cpp)
913 return (combo_class_buf[combobuf[combo].type].ladder_pass);
914 }
915
916 // Returns the letter of the warp combo.
917 int32_t zmap::warpindex(int32_t combo)
918 {
919 switch(combobuf[combo].type)
920 {
921 case cCAVE:
922 case cPIT:
923 case cSTAIR:
924 case cCAVE2:
925 case cSWIMWARP:
926 case cDIVEWARP:
927 case cSWARPA:
928 return 0;
929
930 case cCAVEB:
931 case cPITB:
932 case cSTAIRB:
933 case cCAVE2B:
934 case cSWIMWARPB:
935 case cDIVEWARPB:
936 case cSWARPB:
937 return 1;
938
939 case cCAVEC:
940 case cPITC:
941 case cSTAIRC:
942 case cCAVE2C:
943 case cSWIMWARPC:
944 case cDIVEWARPC:
945 case cSWARPC:
946 return 2;
947
948 case cCAVED:
949 case cPITD:
950 case cSTAIRD:
951 case cCAVE2D:
952 case cSWIMWARPD:
953 case cDIVEWARPD:
954 case cSWARPD:
955 return 3;
956
957 case cPITR:
958 case cSTAIRR:
959 case cSWARPR:
960 return 4;
961 }
962
963 return -1;
964
965 }
966
967 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
968 {
969 if(top)
970 line(dest,x,y,x+15,y,c);
971 rectfill(dest,x,y,x+3,y+15,c);
972 rectfill(dest,x+12,y,x+15,y+15,c);
973 rectfill(dest,x+4,y+2,x+11,y+5,c);
974 rectfill(dest,x+4,y+10,x+11,y+13,c);
975 }
976
977 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
978 {
979 line(dest,x,y,x+15,y,c);
980 }
981
982 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
983 {
984 int32_t cx = COMBOX(pos);
985 int32_t cy = COMBOY(pos);
986
987 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
988
989 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
990
991 int32_t bridgedetected = 0;
992
993 for(int32_t i=0; i<4; i++)
994 {
995 int32_t tx=((i&2)<<2)+x;
996 int32_t ty=((i&1)<<3)+y;
997 int32_t tx2=((i&2)<<2)+cx;
998 int32_t ty2=((i&1)<<3)+cy;
999 for (int32_t m = layer; m <= 1; m++)
1000 {
1001 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1002 {
1003 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1004 {
1005 bridgedetected |= (1<<i);
1006 }
1007 }
1008 else
1009 {
1010 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1011 {
1012 bridgedetected |= (1<<i);
1013 }
1014 }
1015 }
1016 if (bridgedetected & (1<<i))
1017 {
1018 if (i >= 3) break;
1019 else continue;
1020 }
1021 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1022 {
1023 for(int32_t k=0; k<8; k+=2)
1024 for(int32_t j=0; j<8; j+=2)
1025 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1026 }
1027 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1028 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1029
1030 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1031 {
1032 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1033 {
1034 for(int32_t k=0; k<8; k+=2)
1035 for(int32_t j=0; j<8; j+=2)
1036 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1037 }
1038 else
1039 {
1040 int32_t color = COLOR_SOLID;
1041
1042 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1043 color=vc(6);
1044 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1045 color=vc(7);
1046
1047 rectfill(dest,tx,ty,tx+7,ty+7,color);
1048 }
1049 }
1050 }
1051
1052 bridgedetected = 0;
1053 for(int32_t i=0; i<4; i++)
1054 {
1055 int32_t tx2=((i&2)<<2)+cx;
1056 int32_t ty2=((i&1)<<3)+cy;
1057 for (int32_t m = 0; m <= 1; m++)
1058 {
1059 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1060 {
1061 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1062 {
1063 bridgedetected |= (1<<i);
1064 }
1065 }
1066 else
1067 {
1068 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1069 {
1070 bridgedetected |= (1<<i);
1071 }
1072 }
1073 }
1074 }
1075
1076 // Draw damage combos
1077 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1078 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1079 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1080 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1081 || combo_class_buf[c1.type].modify_hp_amount
1082 || combo_class_buf[c2.type].modify_hp_amount;
1083
1084 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1085
1086 if(dmg)
1087 {
1088 if (bridgedetected <= 0)
1089 {
1090 for(int32_t k=0; k<16; k+=2)
1091 for(int32_t j=0; j<16; j+=2)
1092 if(((k+j)/2)%2)
1093 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1094 }
1095 else
1096 {
1097 for(int32_t i=0; i<4; i++)
1098 {
1099 if (!(bridgedetected & (1<<i)))
1100 {
1101 int32_t tx=((i&2)<<2)+x;
1102 int32_t ty=((i&1)<<3)+y;
1103 for(int32_t k=0; k<8; k+=2)
1104 for(int32_t j=0; j<8; j+=2)
1105 if(((k+j)/2)%2)
1106 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1107 }
1108 }
1109 }
1110 }
1111
1112 if(c.type == cSLOPE)
1113 {
1114 slope_info s(c, x, y);
1115 s.draw(dest, 0, 0, COLOR_SLOPE);
1116 }
1117 auto fl0 = MAPFLAG2(-1,cx,cy);
1118 auto fl1 = MAPFLAG2(0,cx,cy);
1119 auto fl2 = MAPFLAG2(1,cx,cy);
1120 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1121 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1122 {
1123 bool top = false;
1124 if(cy)
1125 {
1126 top = true;
1127 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1128 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1129 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1130 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1131 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1132 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1133 {
1134 top = false;
1135 }
1136 }
1137 draw_ladder(dest,x,y,COLOR_LADDER,top);
1138 }
1139 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1140 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1141 {
1142 draw_platform(dest,x,y,COLOR_LADDER);
1143 }
1144 }
1145
1146 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1147 {
1148 int32_t cx = COMBOX(pos);
1149 int32_t cy = COMBOY(pos);
1150
1151 if (screen < 0) return;
1152 if (map < 0) return;
1153
1154 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1155
1156 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1157
1158 int32_t bridgedetected = 0;
1159 for(int32_t i=0; i<4; i++)
1160 {
1161 int32_t tx=((i&2)<<2)+x;
1162 int32_t ty=((i&1)<<3)+y;
1163 int32_t tx2=((i&2)<<2)+cx;
1164 int32_t ty2=((i&1)<<3)+cy;
1165 for (int32_t m = layer; m <= 1; m++)
1166 {
1167 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1168 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1169 {
1170 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1171 {
1172 bridgedetected |= (1<<i);
1173 }
1174 }
1175 else
1176 {
1177 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1178 {
1179 bridgedetected |= (1<<i);
1180 }
1181 }
1182 }
1183 if (bridgedetected & (1<<i))
1184 {
1185 continue;
1186 }
1187 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1188 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1189
1190
1191 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1192 {
1193 for(int32_t k=0; k<8; k+=2)
1194 for(int32_t j=0; j<8; j+=2)
1195 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1196 }
1197 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1198 {
1199 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1200 {
1201 for(int32_t k=0; k<8; k+=2)
1202 for(int32_t j=0; j<8; j+=2)
1203 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1204 }
1205 else
1206 {
1207 int32_t color = COLOR_SOLID;
1208
1209 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1210 color=vc(6);
1211 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1212 color=vc(7);
1213
1214 rectfill(dest,tx,ty,tx+7,ty+7,color);
1215 }
1216 }
1217 }
1218
1219 bridgedetected = 0;
1220 for(int32_t i=0; i<4; i++)
1221 {
1222 int32_t tx2=((i&2)<<2)+cx;
1223 int32_t ty2=((i&1)<<3)+cy;
1224 for (int32_t m = 0; m <= 1; m++)
1225 {
1226 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1227 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1228 {
1229 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1230 {
1231 bridgedetected |= (1<<i);
1232 }
1233 }
1234 else
1235 {
1236 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1237 {
1238 bridgedetected |= (1<<i);
1239 }
1240 }
1241 }
1242 }
1243
1244 // Draw damage combos
1245 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1246 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1247 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1248 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1249 || combo_class_buf[c1.type].modify_hp_amount
1250 || combo_class_buf[c2.type].modify_hp_amount;
1251
1252 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1253
1254 if(dmg)
1255 {
1256 if (bridgedetected <= 0)
1257 {
1258 for(int32_t k=0; k<16; k+=2)
1259 for(int32_t j=0; j<16; j+=2)
1260 if(((k+j)/2)%2)
1261 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1262 }
1263 else
1264 {
1265 for(int32_t i=0; i<4; i++)
1266 {
1267 if (!(bridgedetected & (1<<i)))
1268 {
1269 int32_t tx=((i&2)<<2)+x;
1270 int32_t ty=((i&1)<<3)+y;
1271 for(int32_t k=0; k<8; k+=2)
1272 for(int32_t j=0; j<8; j+=2)
1273 if(((k+j)/2)%2)
1274 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1275 }
1276 }
1277 }
1278 }
1279
1280 if(c.type == cSLOPE)
1281 {
1282 slope_info s(c, x, y);
1283 s.draw(dest, 0, 0, COLOR_SLOPE);
1284 }
1285 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1286 auto fl1 = MAPFLAG3(map,screen,0,pos);
1287 auto fl2 = MAPFLAG3(map,screen,1,pos);
1288 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1289 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1290 {
1291 bool top = false;
1292 if(cy)
1293 {
1294 top = true;
1295 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1296 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1297 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1298 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1299 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1300 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1301 {
1302 top = false;
1303 }
1304 }
1305 draw_ladder(dest,x,y,COLOR_LADDER,top);
1306 }
1307 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1308 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1309 {
1310 draw_platform(dest,x,y,COLOR_LADDER);
1311 }
1312 }
1313
1314 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1315 {
1316 const newcombo& c = combobuf[cmbdat];
1317
1318 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1319
1320 for(int32_t i=0; i<4; i++)
1321 {
1322 int32_t tx=((i&2)<<2)+x;
1323 int32_t ty=((i&1)<<3)+y;
1324
1325 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1326 {
1327 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1328 {
1329 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1330 }
1331 else
1332 {
1333 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1334 }
1335 }
1336
1337
1338 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1339 {
1340 for(int32_t k=0; k<8; k+=2)
1341 for(int32_t j=0; j<8; j+=2)
1342 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1343 }
1344 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1345 {
1346 if(c.type==cLADDERHOOKSHOT)
1347 {
1348 for(int32_t k=0; k<8; k+=2)
1349 for(int32_t j=0; j<8; j+=2)
1350 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1351 }
1352 else
1353 {
1354 int32_t color = COLOR_SOLID;
1355
1356 if(c.type==cLADDERONLY)
1357 color=vc(6);
1358 else if(c.type==cHOOKSHOTONLY)
1359 color=vc(7);
1360
1361 rectfill(dest,tx,ty,tx+7,ty+7,color);
1362 }
1363 }
1364
1365 // Draw damage combos
1366 if(combo_class_buf[c.type].modify_hp_amount != 0)
1367 {
1368 for(int32_t k=0; k<8; k+=2)
1369 for(int32_t j=0; j<8; j+=2)
1370 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1371 }
1372 }
1373
1374 if(c.type == cSLOPE)
1375 {
1376 slope_info s(c, 0, 0);
1377 zfix const& slope = s.slope();
1378
1379 BITMAP* sub = create_bitmap_ex(8,16,16);
1380 clear_bitmap(sub);
1381 s.draw(sub, 0, 0, COLOR_SLOPE);
1382 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1383 destroy_bitmap(sub);
1384 }
1385 if(c.flag == mfSIDEVIEWLADDER)
1386 {
1387 draw_ladder(dest,x,y,COLOR_LADDER);
1388 }
1389 else if(c.flag == mfSIDEVIEWPLATFORM)
1390 {
1391 draw_platform(dest,x,y,COLOR_LADDER);
1392 }
1393 }
1394
1395 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1396 {
1397 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1398 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1399 }
1400 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1401 {
1402
1403 newcombo const& c = combobuf[cmbdat];
1404
1405 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1406 {
1407 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1408 // text_mode(-1);
1409 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1410 if(sflag)
1411 {
1412 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1413 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1414 }
1415
1416 if(c.flag)
1417 {
1418 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1419 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1420 }
1421 }
1422
1423 if(flags&cCSET)
1424 {
1425 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1426 // text_mode(inv?vc(15):vc(0));
1427 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1428 }
1429 else if(flags&cCTYPE)
1430 {
1431 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1432 // text_mode(inv?vc(15):vc(0));
1433 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1434 }
1435 }
1436
1437 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1438 {
1439 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1440
1441 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1442 if(repos)
1443 {
1444 combotile_override_x = x+(8*(scale-1));
1445 combotile_override_y = y+(8*(scale-1));
1446 }
1447 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1448 if(repos) combotile_override_x = combotile_override_y = -1;
1449 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1450 destroy_bitmap(b);
1451 }
1452 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1453 {
1454 static newcombo nilcombo;
1455 nilcombo.tile = 0;
1456
1457 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1458
1459 if(c.tile==0)
1460 {
1461 rectfill(dest,x,y,x+15,y+15,vc(0));
1462 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1463 return;
1464 }
1465
1466 putcombo(dest,x,y,cmbdat,cset);
1467
1468 /* moved to put_walkflags
1469 for(int32_t i=0; i<4; i++) {
1470
1471 int32_t tx=((i&2)<<2)+x;
1472 int32_t ty=((i&1)<<3)+y;
1473 if((flags&cWALK) && (c.walk&(1<<i)))
1474 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1475 }
1476 */
1477
1478 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1479 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1480 {
1481 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1482 // text_mode(-1);
1483 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1484 if(sflag)
1485 {
1486 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1487 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1488 }
1489
1490 if(combobuf[cmbdat].flag)
1491 {
1492 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1493 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1494 }
1495 }
1496
1497 if(flags&cWALK)
1498 {
1499 put_walkflags(dest,x,y,cmbdat,0);
1500 }
1501
1502 if(flags&cCSET)
1503 {
1504 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1505 // text_mode(inv?vc(15):vc(0));
1506 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1507 }
1508 else if(flags&cCTYPE)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 // text_mode(inv?vc(15):vc(0));
1512 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1513 }
1514 }
1515 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1516 {
1517 auto blitx = 1 + (slot % 16) * 17;
1518 auto blity = 1 + (slot / 16) * 17;
1519 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1520 }
1521
1522
1523 void copy_mapscr(mapscr *dest, const mapscr *src)
1524 {
1525 if(!dest || !src) return;
1526 *dest = *src;
1527 }
1528
1529 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1530 {
1531 int32_t x=0,y=0;
1532 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1533
1534 switch(side)
1535 {
1536 case up:
1537 case down:
1538 x=((pos&15)<<4)+xofs;
1539 y=(ignorepos?0:(pos&0xF0))+yofs;
1540 break;
1541
1542 case left:
1543 case right:
1544 x=(ignorepos?0:((pos&15)<<4))+xofs;
1545 y=(pos&0xF0)+yofs;
1546 break;
1547 }
1548
1549 switch(type)
1550 {
1551 case dt_lock:
1552 case dt_shut:
1553 case dt_boss:
1554 case dt_bomb:
1555 switch(side)
1556 {
1557 case up:
1558 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1559 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1560 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1561 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1562 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1563 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1564 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1565 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1566 break;
1567
1568 case down:
1569 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1570 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1571 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1572 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1573 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1574 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1575 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1576 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1577 break;
1578
1579 case left:
1580 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1581 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1582 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1583 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1584 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1585 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1586
1587 if(x+16 >= dest->w)
1588 break;
1589
1590 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1591 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1592 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1593 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1594 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1595 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1596 break;
1597
1598 case right:
1599
1600 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1601 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1602 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1603 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1604 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1605 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1606
1607 if(x+16 <= 0)
1608 break;
1609
1610 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1611 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1612 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1613 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1614 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1615 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1616 break;
1617 }
1618
1619 break;
1620
1621 case dt_pass:
1622 case dt_wall:
1623 case dt_walk:
1624 default:
1625 break;
1626 }
1627 }
1628
1629 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1630 {
1631 int32_t x=((pos&15)<<4)+xofs;
1632 int32_t y=(pos&0xF0)+yofs;
1633 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1634
1635
1636 switch(side)
1637 {
1638 case up:
1639 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1640 {
1641 overcombo(dest,x,y,
1642 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1643 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1644 }
1645
1646 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1647 {
1648 overcombo(dest,x+16,y,
1649 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1650
1651 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1652 }
1653
1654 break;
1655
1656 case down:
1657 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1658 {
1659 overcombo(dest,x,y,
1660 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1661 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1662 }
1663
1664 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1665 {
1666 overcombo(dest,x+16,y,
1667 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1668 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1669 }
1670
1671 break;
1672
1673 case left:
1674 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1675 {
1676 overcombo(dest,x,y,
1677 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1678 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1679 }
1680
1681 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1682 {
1683 overcombo(dest,x,y+16,
1684 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1685 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1686 }
1687
1688 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1689 {
1690 overcombo(dest,x,y+32,
1691 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1692 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1693 }
1694
1695 break;
1696
1697 case right:
1698 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1699 {
1700 overcombo(dest,x,y,
1701 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1702 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1703 }
1704
1705 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1706 {
1707 overcombo(dest,x,y+16,
1708
1709 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1711 }
1712
1713 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1714 {
1715 overcombo(dest,x,y+32,
1716 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1718 }
1719
1720 break;
1721 }
1722 }
1723
1724 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1725 {
1726 word cmbcheck1, cmbcheck2;
1727 newcombo combocheck1, combocheck2;
1728 combocheck1 = combobuf[0];
1729 combocheck2 = combobuf[0];
1730 combocheck1.walk = 0;
1731 combocheck2.walk = 0;
1732
1733 int32_t layermap, layerscreen;
1734
1735 switch(dir)
1736 {
1737 case up:
1738 {
1739 if(i>15) //not top row of combos
1740 {
1741 return false;
1742 }
1743
1744 if(scr<16) //top row of screens
1745 {
1746 return false;
1747
1748 }
1749
1750 //check main screen
1751 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1752 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1753 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1754 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1755
1756 //check layer 1
1757 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1758
1759 if(layermap>-1 && layermap<map_count)
1760 {
1761 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1762 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1763 if (combobuf[cmbcheck1].type == cBRIDGE)
1764 {
1765 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1766 {
1767 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1768 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1769 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1770 }
1771 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1772 }
1773 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1774 }
1775
1776 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1777
1778 if(layermap>-1 && layermap<map_count)
1779 {
1780 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1781 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1782 if (combobuf[cmbcheck2].type == cBRIDGE)
1783 {
1784 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1785 {
1786 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1787 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1788 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1789 }
1790 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1791 }
1792 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1793 }
1794
1795 //check layer 2
1796 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1797
1798 if(layermap>-1 && layermap<map_count)
1799 {
1800 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1801
1802 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1803 if (combobuf[cmbcheck2].type == cBRIDGE)
1804 {
1805 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1806 {
1807 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1808 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1809 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1810 }
1811 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1812 }
1813 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1814 }
1815
1816 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1817
1818 if(layermap>-1 && layermap<map_count)
1819 {
1820 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1821 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1822 if (combobuf[cmbcheck2].type == cBRIDGE)
1823 {
1824 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1825 {
1826 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1827 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1828 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1829 }
1830 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1831 }
1832 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1833 }
1834
1835 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1836 {
1837 return true;
1838 }
1839
1840 break;
1841 }
1842 case down:
1843 {
1844 if(i<160) //not bottom row of combos
1845 {
1846 return false;
1847 }
1848
1849 if(scr>111) //bottom row of screens
1850 {
1851 return false;
1852 }
1853
1854 //check main screen
1855 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1856 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1857 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1858 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1859
1860
1861 //check layer 1
1862 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1863
1864 if(layermap>-1 && layermap<map_count)
1865 {
1866 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1867 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1868 if (combobuf[cmbcheck1].type == cBRIDGE)
1869 {
1870 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1871 {
1872 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1873 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1874 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1875 }
1876 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1877 }
1878 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1879 }
1880
1881 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1882
1883 if(layermap>-1 && layermap<map_count)
1884 {
1885 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1886 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1887 if (combobuf[cmbcheck2].type == cBRIDGE)
1888 {
1889 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1890 {
1891 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1892 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1893 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1894 }
1895 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1896 }
1897 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1898 }
1899
1900 //check layer 2
1901 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1902
1903 if(layermap>-1 && layermap<map_count)
1904 {
1905 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1906 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1907 if (combobuf[cmbcheck1].type == cBRIDGE)
1908 {
1909 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1910 {
1911 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1912 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1913 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1914 }
1915 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1916 }
1917 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1918 }
1919
1920 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1921
1922 if(layermap>-1 && layermap<map_count)
1923 {
1924 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1925 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1926 if (combobuf[cmbcheck2].type == cBRIDGE)
1927 {
1928 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1929 {
1930 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1931 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1932 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1933 }
1934 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1935 }
1936 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1937 }
1938
1939 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
1940 {
1941 return true;
1942 }
1943
1944 break;
1945 }
1946 case left:
1947 {
1948 if((i&0xF)!=0) //not left column of combos
1949 {
1950 return false;
1951 }
1952
1953 if((scr&0xF)==0) //left column of screens
1954 {
1955 return false;
1956 }
1957
1958 //check main screen
1959 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
1960 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
1961 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1962 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1963
1964 //check layer 1
1965 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1966
1967 if(layermap>-1 && layermap<map_count)
1968 {
1969 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1970 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1971 if (combobuf[cmbcheck1].type == cBRIDGE)
1972 {
1973 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1974 {
1975 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1976 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1977 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1978 }
1979 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1980 }
1981 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1982 }
1983
1984 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
1985
1986 if(layermap>-1 && layermap<map_count)
1987 {
1988 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
1989 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
1990 if (combobuf[cmbcheck2].type == cBRIDGE)
1991 {
1992 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1993 {
1994 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1995 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1996 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1997 }
1998 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1999 }
2000 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2001 }
2002
2003 //check layer 2
2004 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2005
2006 if(layermap>-1 && layermap<map_count)
2007 {
2008 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2009 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2010 if (combobuf[cmbcheck1].type == cBRIDGE)
2011 {
2012 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2013 {
2014 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2015 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2016 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2017 }
2018 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2019 }
2020 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2021 }
2022
2023 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2024
2025 if(layermap>-1 && layermap<map_count)
2026 {
2027 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2028 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2029 if (combobuf[cmbcheck2].type == cBRIDGE)
2030 {
2031 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2032 {
2033 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2034 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2035 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2036 }
2037 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2038 }
2039 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2040 }
2041
2042 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2043 {
2044 return true;
2045 }
2046
2047 break;
2048 }
2049 case right:
2050 {
2051 if((i&0xF)!=15) //not right column of combos
2052 {
2053 return false;
2054 }
2055
2056 if((scr&0xF)==15) //right column of screens
2057 {
2058 return false;
2059 }
2060
2061 //check main screen
2062 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2063 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2064 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2065 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2066
2067 //check layer 1
2068 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2069
2070 if(layermap>-1 && layermap<map_count)
2071 {
2072 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2073 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2074 if (combobuf[cmbcheck1].type == cBRIDGE)
2075 {
2076 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2077 {
2078 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2079 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2080 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2081 }
2082 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2083 }
2084 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2085 }
2086
2087 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2088
2089 if(layermap>-1 && layermap<map_count)
2090 {
2091 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2092 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2093 if (combobuf[cmbcheck2].type == cBRIDGE)
2094 {
2095 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2096 {
2097 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2098 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2099 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2100 }
2101 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2102 }
2103 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2104 }
2105
2106 //check layer 2
2107 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2108
2109 if(layermap>-1 && layermap<map_count)
2110 {
2111 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2112 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2113 if (combobuf[cmbcheck1].type == cBRIDGE)
2114 {
2115 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2116 {
2117 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2118 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2119 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2120 }
2121 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2122 }
2123 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2124 }
2125
2126 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2127
2128 if(layermap>-1 && layermap<map_count)
2129 {
2130 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2131
2132 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2133 if (combobuf[cmbcheck2].type == cBRIDGE)
2134 {
2135 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2136 {
2137 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2138 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2139 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2140 }
2141 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2142 }
2143 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2144 }
2145
2146 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2147 {
2148 return true;
2149 }
2150
2151 break;
2152 }
2153 }
2154
2155 return false;
2156 }
2157
2158 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2159 {
2160 int32_t checkcombo;
2161
2162 if(alignment_arrow_timer>31)
2163 {
2164 if(scr<0)
2165 {
2166 scr=currscr;
2167 }
2168
2169 if((scr<128)) //do the misalignment arrows
2170 {
2171 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2172 {
2173 if(misaligned(currmap, scr, checkcombo, up))
2174 {
2175 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2176 }
2177 }
2178
2179 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2180 {
2181 if(misaligned(currmap, scr, checkcombo, down))
2182 {
2183 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2184 }
2185 }
2186
2187 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2188 {
2189 if(misaligned(currmap, scr, checkcombo, left))
2190 {
2191 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2192 }
2193 }
2194
2195 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2196 {
2197 if(misaligned(currmap, scr, checkcombo, right))
2198 {
2199 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2200 }
2201 }
2202
2203 int32_t tempalign;
2204
2205 //check top left corner
2206 checkcombo=0;
2207 tempalign=0;
2208 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2209 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2210
2211 switch(tempalign)
2212 {
2213 case 0:
2214 break;
2215
2216 case 1: //up
2217 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2218 break;
2219
2220 case 2: //left
2221 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2222 break;
2223
2224 case 3: //up-left
2225 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2226 break;
2227 }
2228
2229 //check top right corner
2230 checkcombo=15;
2231 tempalign=0;
2232 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2233 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2234
2235 switch(tempalign)
2236 {
2237 case 0:
2238 break;
2239
2240 case 1: //up
2241 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2242 break;
2243
2244 case 2: //right
2245 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2246 break;
2247
2248 case 3: //up-right
2249 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2250 break;
2251 }
2252
2253 //check bottom left corner
2254 checkcombo=160;
2255 tempalign=0;
2256 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2257 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2258
2259 switch(tempalign)
2260 {
2261 case 0:
2262 break;
2263
2264 case 1: //down
2265 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2266 break;
2267
2268 case 2: //left
2269 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2270 break;
2271
2272 case 3: //down-left
2273 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2274 break;
2275 }
2276
2277 //check bottom right corner
2278
2279 checkcombo=175;
2280 tempalign=0;
2281 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2282 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2283
2284 switch(tempalign)
2285 {
2286 case 0:
2287 break;
2288
2289 case 1: //down
2290 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2291 break;
2292
2293 case 2: //right
2294 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2295 break;
2296
2297 case 3: //down-right
2298 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2299 break;
2300 }
2301 }
2302 }
2303 }
2304
2305 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2306 {
2307 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2308 }
2309
2310 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2311 {
2312 if (map < 0 || screen < 0) return 0;
2313
2314 if(pos>175 || pos < 0)
2315 return 0;
2316
2317 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2318
2319 if(m->valid==0) return 0;
2320
2321 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2322
2323 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2324
2325 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2326
2327 if(scr->valid==0) return 0;
2328
2329 return scr->data[pos]; // entire combo code
2330 }
2331
2332 // Takes array index layer num., not actual layer num.
2333 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2334 {
2335 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2336
2337 if(map<0)
2338 map=currmap;
2339
2340 if(scr<0)
2341 scr=currscr;
2342
2343 mapscr *screen1;
2344
2345 if(prv_mode)
2346 {
2347 screen1=get_prvscr();
2348 }
2349 else
2350 {
2351 screen1=AbsoluteScr(currmap,currscr);
2352 }
2353
2354 int32_t layermap;
2355 layermap=screen1->layermap[lyr]-1;
2356
2357 if(layermap<0 || layermap >= map_count) return 0;
2358
2359 mapscr *layer;
2360
2361 if(prv_mode)
2362 layer = &prvlayers[lyr];
2363 else
2364 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2365
2366 int32_t combo = COMBOPOS(x,y);
2367
2368 if(combo>175 || combo < 0)
2369 return 0;
2370
2371 return layer->data[combo];
2372 }
2373
2374 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2375 {
2376 if(map<0)
2377 map=currmap;
2378
2379 if(scr<0)
2380 scr=currscr;
2381
2382 mapscr *screen1;
2383
2384 if(prv_mode)
2385 {
2386 screen1=get_prvscr();
2387 }
2388 else
2389 {
2390 screen1=AbsoluteScr(currmap,currscr);
2391 }
2392
2393 x = vbound(x, 0, 16*16);
2394 y = vbound(y, 0, 11*16);
2395 int32_t combo = COMBOPOS(x,y);
2396
2397 if(combo>175 || combo < 0)
2398 return 0;
2399
2400 return screen1->data[combo];
2401 }
2402
2403 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2404 {
2405 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2406 }
2407
2408 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2409 {
2410 if (map < 0 || screen < 0) return 0;
2411
2412 if(pos>175 || pos < 0)
2413 return 0;
2414
2415 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2416
2417 if(m->valid==0) return 0;
2418
2419 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2420
2421 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2422
2423 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2424
2425 if(scr->valid==0) return 0;
2426
2427 return scr->sflag[pos]; // entire combo code
2428 }
2429
2430 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2431 {
2432 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2433
2434 if(map<0)
2435 map=currmap;
2436
2437 if(scr<0)
2438 scr=currscr;
2439
2440 mapscr *screen1;
2441
2442 if(prv_mode)
2443 {
2444 screen1=get_prvscr();
2445 }
2446 else
2447 {
2448 screen1=AbsoluteScr(currmap,currscr);
2449 }
2450
2451 int32_t layermap;
2452 layermap=screen1->layermap[lyr]-1;
2453
2454 if(layermap<0 || layermap >= map_count) return 0;
2455
2456 mapscr *layer;
2457
2458 if(prv_mode)
2459 layer = &prvlayers[lyr];
2460 else
2461 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2462
2463 int32_t combo = COMBOPOS(x,y);
2464
2465 if(combo>175 || combo < 0)
2466 return 0;
2467
2468 return layer->sflag[combo];
2469 }
2470
2471 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2472 {
2473 if(map<0)
2474 map=currmap;
2475
2476 if(scr<0)
2477 scr=currscr;
2478
2479 mapscr *screen1;
2480
2481 if(prv_mode)
2482 {
2483 screen1=get_prvscr();
2484 }
2485 else
2486 {
2487 screen1=AbsoluteScr(currmap,currscr);
2488 }
2489
2490 x = vbound(x, 0, 16*16);
2491 y = vbound(y, 0, 11*16);
2492 int32_t combo = COMBOPOS(x,y);
2493
2494 if(combo>175 || combo < 0)
2495 return 0;
2496
2497 return screen1->sflag[combo];
2498 }
2499
2500 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2501 {
2502 mapscr *layers[7];
2503 mapscr *basescr;
2504 if(prv_mode)
2505 {
2506 layers[0] = &prvscr;
2507 basescr = layers[0];
2508 for(auto q = 1; q < 7; ++q)
2509 {
2510 if(prvlayers[q-1].valid)
2511 layers[q] = &(prvlayers[q-1]);
2512 else layers[q] = NULL;
2513 }
2514 }
2515 else
2516 {
2517 layers[0] = AbsoluteScr(currmap, currscr);
2518 basescr = layers[0];
2519 for(auto q = 1; q < 7; ++q)
2520 {
2521 int32_t lmap = basescr->layermap[q-1]-1;
2522 int32_t lscr = basescr->layerscreen[q-1];
2523 if(lmap < 0)
2524 layers[q] = NULL;
2525 else layers[q] = AbsoluteScr(lmap, lscr);
2526 }
2527 }
2528 for(auto q = 0; q < 7; ++q)
2529 {
2530 if(!layers[q]) continue;
2531 for(auto pos = 0; pos < 176; ++pos)
2532 {
2533 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2534 if(cmb.type == cTORCH)
2535 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2536 }
2537 }
2538 word maxffc = basescr->numFFC();
2539 for(auto q = 0; q < maxffc; ++q)
2540 {
2541 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2542 if(cmb.type == cTORCH)
2543 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2544 }
2545 }
2546
2547 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2548 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2549 {
2550 newcombo const& cmb = combobuf[cid];
2551 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2552 if(dither)
2553 {
2554 if (LayerDitherSz == 0)
2555 return;
2556 BITMAP* buf = create_bitmap_ex(8,16,16);
2557 clear_bitmap(buf);
2558 overcombo(buf,0,0,cid,cset);
2559 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2560 if(over)
2561 {
2562 if(transp)
2563 {
2564 color_map = &trans_table2;
2565 draw_trans_sprite(dest, buf, x, y);
2566 color_map = &trans_table;
2567 }
2568 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2569 }
2570 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2571 destroy_bitmap(buf);
2572 }
2573 else if(over)
2574 {
2575 if(transp)
2576 overcombotranslucent(dest,x,y,cid,cset,0);
2577 else overcombo(dest,x,y,cid,cset);
2578 }
2579 else put_combo(dest,x,y,cid,cset,flags,sflag);
2580 }
2581 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2582 {
2583 if(!md) return;
2584 for (int32_t i = 0; i < 176; i++)
2585 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2586 }
2587 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2588 {
2589 if(!md) return;
2590 for (int32_t i = 0; i < 176; i++)
2591 {
2592 int data = md->data[i];
2593 if(combo_class_buf[combobuf[data].type].overhead)
2594 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2595 }
2596 }
2597 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2598 {
2599 if(!LayerMaskInt[lyr])
2600 return nullptr;
2601 if(lyr == 0)
2602 return basescr;
2603 int layermap = basescr->layermap[lyr-1]-1;
2604
2605 if(layermap>-1 && layermap<map_count)
2606 {
2607 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2608 return &TheMaps[layerscreen];
2609 }
2610 return nullptr;
2611 }
2612 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2613 {
2614 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2615 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2616
2617 if(map<0)
2618 map=currmap;
2619
2620 if(scr<0)
2621 scr=currscr;
2622
2623 mapscr *basescr;
2624 mapscr* layers[7] = {nullptr};
2625
2626 if(prv_mode)
2627 {
2628 hl_layer = -1;
2629 basescr=get_prvscr();
2630 }
2631 else
2632 {
2633 basescr=AbsoluteScr(map,scr);
2634 }
2635 layers[0] = _zmap_get_lyr_checked(0,basescr);
2636 for(int lyr = 1; lyr < 7; ++lyr)
2637 {
2638 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2639 : _zmap_get_lyr_checked(lyr,basescr);
2640 }
2641
2642 int32_t layermap, layerscreen;
2643 if(CurrentLayer < 1)
2644 layermap = -1;
2645 else
2646 {
2647 layermap=basescr->layermap[CurrentLayer-1]-1;
2648
2649 if(layermap<0)
2650 CurrentLayer=0;
2651 }
2652
2653 if(!(basescr->valid&mVALID))
2654 {
2655 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2656 rectfill(dest,x,y,x+255,y+175,vc(1));
2657
2658 if(ShowMisalignments)
2659 {
2660 check_alignments(dest,x,y,scr);
2661 }
2662
2663 return;
2664 }
2665
2666 if(LayerMaskInt[0]==0)
2667 {
2668 byte bgfill = 0;
2669 if (LayerDitherBG > -1)
2670 bgfill = vc(LayerDitherBG);
2671 rectfill(dest,x,y,x+255,y+175,bgfill);
2672 }
2673
2674 resize_mouse_pos=true;
2675 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2676 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2677
2678 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2679 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2680
2681 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2682
2683 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2684
2685 for(int32_t i=MAXFFCS-1; i>=0; i--)
2686 {
2687 if(basescr->ffcs[i].data)
2688 {
2689 if(!(basescr->ffcs[i].flags&ffc_changer))
2690 {
2691 if(!(basescr->ffcs[i].flags&ffc_overlay))
2692 {
2693 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2694 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2695
2696 if(basescr->ffcs[i].flags&ffc_trans)
2697 {
2698 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2699 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2700 }
2701 else
2702 {
2703 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2704 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2705 }
2706 }
2707 }
2708 }
2709 }
2710
2711 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2712 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2713
2714 int32_t doortype[4];
2715
2716 for(int32_t i=0; i<4; i++)
2717 {
2718 switch(basescr->door[i])
2719 {
2720 case dOPEN:
2721 doortype[i]=dt_pass;
2722 break;
2723
2724 case dLOCKED:
2725 doortype[i]=dt_lock;
2726 break;
2727
2728 case d1WAYSHUTTER:
2729 case dSHUTTER:
2730 doortype[i]=dt_shut;
2731 break;
2732
2733 case dBOSS:
2734 doortype[i]=dt_boss;
2735 break;
2736
2737 case dBOMB:
2738 doortype[i]=dt_bomb;
2739 break;
2740 }
2741 }
2742
2743 switch(basescr->door[up])
2744 {
2745 case dBOMB:
2746 over_door(dest,39,up,x,y,false, scr);
2747 [[fallthrough]];
2748 case dOPEN:
2749 case dLOCKED:
2750 case d1WAYSHUTTER:
2751 case dSHUTTER:
2752 case dBOSS:
2753 put_door(dest,7,up,doortype[up],x,y,false,scr);
2754 break;
2755
2756 case dWALK:
2757 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2758 {
2759 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2760 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2761 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0]);
2762 }
2763 else
2764
2765 {
2766 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2767 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2768 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0],0,0);
2769 }
2770
2771 break;
2772 }
2773
2774 switch(basescr->door[down])
2775 {
2776 case dBOMB:
2777 over_door(dest,135,down,x,y,false,scr);
2778 [[fallthrough]];
2779 case dOPEN:
2780 case dLOCKED:
2781 case d1WAYSHUTTER:
2782 case dSHUTTER:
2783 case dBOSS:
2784 put_door(dest,151,down,doortype[down],x,y,false,scr);
2785 break;
2786
2787 case dWALK:
2788 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2789 {
2790 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2791 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2792 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1]);
2793 }
2794 else
2795 {
2796 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2797 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2798 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1],0,0);
2799 }
2800
2801 break;
2802 }
2803
2804 switch(basescr->door[left])
2805 {
2806 case dBOMB:
2807 over_door(dest,66,left,x,y,false,scr);
2808 [[fallthrough]];
2809 case dOPEN:
2810 case dLOCKED:
2811 case d1WAYSHUTTER:
2812 case dSHUTTER:
2813 case dBOSS:
2814 put_door(dest,64,left,doortype[left],x,y,false,scr);
2815 break;
2816
2817 case dWALK:
2818 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2819 {
2820 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2821 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2822 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2]);
2823 }
2824 else
2825 {
2826 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2827 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2828 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2],0,0);
2829 }
2830
2831 break;
2832 }
2833
2834 switch(basescr->door[right])
2835 {
2836
2837 case dBOMB:
2838 over_door(dest,77,right,x,y,false,scr);
2839 [[fallthrough]];
2840 case dOPEN:
2841 case dLOCKED:
2842 case d1WAYSHUTTER:
2843 case dSHUTTER:
2844 case dBOSS:
2845 put_door(dest,78,right,doortype[right],x,y,false,scr);
2846 break;
2847
2848 case dWALK:
2849 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2850 {
2851 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2852 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2853 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3]);
2854 }
2855 else
2856 {
2857 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2858 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2859 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3],0,0);
2860 }
2861
2862 break;
2863 }
2864
2865 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2866 {
2867 frame=0;
2868 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2869 }
2870
2871 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2872 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2873 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2874
2875 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2876
2877 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2878 {
2879 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2880 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2881 }
2882 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2883
2884 for(int32_t i=MAXFFCS-1; i>=0; i--)
2885 {
2886 if(basescr->ffcs[i].data)
2887 {
2888 if(!(basescr->ffcs[i].flags&ffc_changer))
2889 {
2890 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2891 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2892
2893 if(basescr->ffcs[i].flags&ffc_overlay)
2894 {
2895 if(basescr->ffcs[i].flags&ffc_trans)
2896 {
2897 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2898 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2899 }
2900 else
2901 {
2902 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2903 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2904 }
2905 }
2906 }
2907 }
2908 }
2909
2910 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2911
2912 for(int32_t i=MAXFFCS-1; i>=0; i--)
2913 if(basescr->ffcs[i].data)
2914 if(basescr->ffcs[i].flags&ffc_changer)
2915 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2916
2917 if(flags&cWALK)
2918 {
2919 if(layers[0])
2920 for(int32_t i=0; i<176; i++)
2921 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2922
2923 for(int32_t k=0; k<2; k++)
2924 {
2925 if(layers[k+1])
2926 for(int32_t i=0; i<176; i++)
2927 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2928 }
2929 for(int32_t i=MAXFFCS-1; i>=0; i--)
2930 {
2931 if(auto data = basescr->ffcs[i].data)
2932 {
2933 if(!(basescr->ffcs[i].flags&ffc_changer))
2934 {
2935 newcombo const& cmb = combobuf[data];
2936 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2937 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2938
2939 if(basescr->ffcs[i].flags&ffc_solid)
2940 {
2941 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2942 }
2943
2944 if(cmb.type == cSLOPE)
2945 {
2946 slope_info s(cmb, tx, ty);
2947 s.draw(dest, 0, 0, COLOR_SLOPE);
2948 }
2949 }
2950 }
2951 }
2952 }
2953
2954 if(flags&cFLAGS)
2955 {
2956 if(LayerMaskInt[CurrentLayer]!=0)
2957 {
2958 for(int32_t i=0; i<176; i++)
2959 {
2960 if(CurrentLayer==0)
2961 {
2962 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2963 }
2964 else
2965 {
2966 if(prv_mode)
2967 {
2968 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2969 }
2970 else
2971 {
2972 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2973
2974 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
2975 {
2976 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2977 TheMaps[_lscr].data[i],
2978 TheMaps[_lscr].cset[i], flags,
2979 TheMaps[_lscr].sflag[i]);
2980 }
2981 }
2982 }
2983 }
2984 }
2985 }
2986
2987 int32_t dark = basescr->flags&cDARK;
2988
2989 if(dark && !(flags&cNODARK)
2990 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2991 {
2992 for(int32_t j=0; j<80; j++)
2993 {
2994 for(int32_t i=0; i<(80)-j; i++)
2995 {
2996 if(((i^j)&1)==0)
2997 {
2998 putpixel(dest,x+i,y+j,vc(blackout_color));
2999 }
3000 }
3001 }
3002 }
3003
3004 if(ShowMisalignments)
3005 {
3006 check_alignments(dest,x,y,scr);
3007 }
3008
3009 resize_mouse_pos=false;
3010 }
3011
3012 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3013 {
3014 if(map<0)
3015 map=currmap;
3016
3017 if(scr<0)
3018 scr=currscr;
3019
3020 mapscr* layer=AbsoluteScr(map,scr);
3021 int32_t layermap=0, layerscreen=0;
3022
3023 if(!(layer->valid&mVALID))
3024 {
3025 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3026 rectfill(dest,x,y,x+255,y+15,vc(1));
3027 return;
3028 }
3029
3030 int32_t dark = layer->flags&4;
3031
3032 resize_mouse_pos=true;
3033
3034 if(LayerMaskInt[0]==0)
3035 {
3036 rectfill(dest,x,y,x+255,y+15,0);
3037 }
3038
3039
3040 for(int32_t k=1; k<3; k++)
3041 {
3042 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3043 {
3044 layermap=layer->layermap[k]-1;
3045
3046 if(layermap>-1 && layermap<map_count)
3047 {
3048 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3049
3050 for(int32_t i=c; i<(c&0xF0)+16; i++)
3051 {
3052 auto data = TheMaps[layerscreen].data[i];
3053 auto cs = TheMaps[layerscreen].cset[i];
3054 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3055 }
3056 }
3057 }
3058 }
3059
3060 if(LayerMaskInt[0]!=0)
3061 {
3062 for(int32_t i=c; i<(c&0xF0)+16; i++)
3063 {
3064 word cmbdat = (i < 176 ? layer->data[i] : 0);
3065 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3066 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3067 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3068 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3069 }
3070 }
3071
3072 for(int32_t k=0; k<2; k++)
3073 {
3074 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3075 {
3076 layermap=layer->layermap[k]-1;
3077
3078 if(layermap>-1 && layermap<map_count)
3079 {
3080 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3081
3082 for(int32_t i=c; i<(c&0xF0)+16; i++)
3083 {
3084 auto data = TheMaps[layerscreen].data[i];
3085 auto cs = TheMaps[layerscreen].cset[i];
3086 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3087 }
3088 }
3089 }
3090 }
3091
3092 int32_t doortype[4];
3093
3094 for(int32_t i=0; i<4; i++)
3095 {
3096 switch(layer->door[i])
3097 {
3098 case dOPEN:
3099 doortype[i]=dt_pass;
3100 break;
3101
3102 case dLOCKED:
3103 doortype[i]=dt_lock;
3104 break;
3105
3106 case d1WAYSHUTTER:
3107 case dSHUTTER:
3108 doortype[i]=dt_shut;
3109 break;
3110
3111 case dBOSS:
3112 doortype[i]=dt_boss;
3113 break;
3114
3115 case dBOMB:
3116 doortype[i]=dt_bomb;
3117 break;
3118 }
3119 }
3120
3121 if(c<16)
3122 {
3123 switch(layer->door[up])
3124 {
3125 case dBOMB:
3126 case dOPEN:
3127 case dLOCKED:
3128 case d1WAYSHUTTER:
3129 case dSHUTTER:
3130 case dBOSS:
3131 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3132 break;
3133 }
3134 }
3135 else if(c>159)
3136 {
3137 switch(layer->door[down])
3138 {
3139 case dBOMB:
3140 case dOPEN:
3141 case dLOCKED:
3142 case d1WAYSHUTTER:
3143 case dSHUTTER:
3144 case dBOSS:
3145 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3146 break;
3147 }
3148 }
3149
3150 for(int32_t k=2; k<4; k++)
3151 {
3152 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3153 {
3154 layermap=layer->layermap[k]-1;
3155
3156 if(layermap>-1 && layermap<map_count)
3157 {
3158 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3159
3160 for(int32_t i=c; i<(c&0xF0)+16; i++)
3161 {
3162 if(layer->layeropacity[k]<255)
3163 {
3164 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3165 }
3166 else
3167 {
3168 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3169 }
3170 }
3171 }
3172 }
3173 }
3174
3175 //Overhead L0
3176 if(LayerMaskInt[0]!=0)
3177 {
3178 for(int32_t i=c; i<(c&0xF0)+16; i++)
3179 {
3180 int32_t ct1=layer->data[i];
3181 int32_t ct3=combobuf[ct1].type;
3182
3183 if(combo_class_buf[ct3].overhead)
3184 {
3185 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3186 }
3187 }
3188 }
3189
3190 //Overhead L1/2
3191 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3192 {
3193 for(int32_t k = 0; k < 2; ++k)
3194 {
3195 if(LayerMaskInt[k+1]!=0)
3196 {
3197 layermap=layer->layermap[k]-1;
3198
3199 if(layermap>-1 && layermap<map_count)
3200 {
3201 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3202 for(int32_t i=c; i<(c&0xF0)+16; i++)
3203 {
3204 auto data = TheMaps[layerscreen].data[i];
3205 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3206 auto cs = TheMaps[layerscreen].cset[i];
3207 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3208 }
3209 }
3210 }
3211 }
3212 }
3213
3214 for(int32_t k=4; k<6; k++)
3215 {
3216 if(LayerMaskInt[k+1]!=0)
3217 {
3218 layermap=layer->layermap[k]-1;
3219
3220 if(layermap>-1 && layermap<map_count)
3221 {
3222 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3223
3224 for(int32_t i=c; i<(c&0xF0)+16; i++)
3225 {
3226 auto data = TheMaps[layerscreen].data[i];
3227 auto cs = TheMaps[layerscreen].cset[i];
3228 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3229 }
3230 }
3231 }
3232 }
3233
3234 if(flags&cWALK)
3235 {
3236 if(LayerMaskInt[0]!=0)
3237 {
3238 for(int32_t i=c; i<(c&0xF0)+16; i++)
3239 {
3240 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3241 }
3242 }
3243
3244 for(int32_t k=0; k<2; k++)
3245 {
3246 if(LayerMaskInt[k+1]!=0)
3247 {
3248 for(int32_t i=c; i<(c&0xF0)+16; i++)
3249 {
3250 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3251 }
3252 }
3253 }
3254 }
3255
3256 if(flags&cFLAGS)
3257 {
3258 if(LayerMaskInt[CurrentLayer]!=0)
3259 {
3260 for(int32_t i=c; i<(c&0xF0)+16; i++)
3261 {
3262 if(CurrentLayer==0)
3263 {
3264 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3265 }
3266 else
3267 {
3268 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3269
3270 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3271 {
3272 if(i < 176)
3273 {
3274 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3275 TheMaps[_lscr].data[i],
3276 TheMaps[_lscr].cset[i], flags|dark,
3277 TheMaps[_lscr].sflag[i]);
3278 }
3279 else
3280 {
3281 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3282 }
3283 }
3284 }
3285 }
3286 }
3287
3288 /*
3289 if (LayerMaskInt[0]!=0) {
3290 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3291 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3292 }
3293 }
3294 */
3295 }
3296
3297 if(ShowMisalignments)
3298 {
3299 if(c<16)
3300 {
3301 check_alignments(dest,x,y,scr);
3302 }
3303 else if(c>159)
3304 {
3305 check_alignments(dest,x,y-160,scr);
3306 }
3307 }
3308
3309 resize_mouse_pos=false;
3310
3311 }
3312
3313 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3314 {
3315 if(map<0)
3316 map=currmap;
3317
3318 if(scr<0)
3319 scr=currscr;
3320
3321 mapscr* layer=AbsoluteScr(map,scr);
3322 int32_t layermap=0, layerscreen=0;
3323
3324 if(!(layer->valid&mVALID))
3325 {
3326 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3327 rectfill(dest,x,y,x+15,y+175,vc(1));
3328 return;
3329 }
3330
3331 int32_t dark = layer->flags&4;
3332
3333 resize_mouse_pos=true;
3334
3335
3336 if(LayerMaskInt[0]==0)
3337 {
3338 rectfill(dest,x,y,x+15,y+175,0);
3339 }
3340
3341
3342 for(int32_t k=1; k<3; k++)
3343 {
3344 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3345 {
3346 layermap=layer->layermap[k]-1;
3347
3348 if(layermap>-1 && layermap<map_count)
3349 {
3350 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3351
3352 for(int32_t i=c; i<176; i+=16)
3353 {
3354 auto data = TheMaps[layerscreen].data[i];
3355 auto cs = TheMaps[layerscreen].cset[i];
3356 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3357 }
3358 }
3359 }
3360 }
3361
3362 if(LayerMaskInt[0]!=0)
3363 {
3364 for(int32_t i=c; i<176; i+=16)
3365 {
3366 word cmbdat = layer->data[i];
3367 byte cmbcset = layer->cset[i];
3368 int32_t cmbflag = layer->sflag[i];
3369 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3370 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3371 }
3372 }
3373
3374 for(int32_t k=0; k<2; k++)
3375 {
3376 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3377 {
3378 layermap=layer->layermap[k]-1;
3379
3380 if(layermap>-1 && layermap<map_count)
3381 {
3382 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3383
3384 for(int32_t i=c; i<176; i+=16)
3385 {
3386 auto data = TheMaps[layerscreen].data[i];
3387 auto cs = TheMaps[layerscreen].cset[i];
3388 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3389 }
3390 }
3391 }
3392 }
3393
3394 int32_t doortype[4];
3395
3396 for(int32_t i=0; i<4; i++)
3397 {
3398 switch(layer->door[i])
3399 {
3400 case dOPEN:
3401 doortype[i]=dt_pass;
3402 break;
3403
3404 case dLOCKED:
3405 doortype[i]=dt_lock;
3406 break;
3407
3408 case d1WAYSHUTTER:
3409 case dSHUTTER:
3410 doortype[i]=dt_shut;
3411 break;
3412
3413 case dBOSS:
3414 doortype[i]=dt_boss;
3415 break;
3416
3417 case dBOMB:
3418 doortype[i]=dt_bomb;
3419 break;
3420 }
3421 }
3422
3423 if((c&0x0F)==0)
3424 {
3425 switch(layer->door[left])
3426 {
3427
3428 case dBOMB:
3429 case dOPEN:
3430 case dLOCKED:
3431 case d1WAYSHUTTER:
3432 case dSHUTTER:
3433 case dBOSS:
3434 // put_door(dest,64,left,doortype[left],x+256,y,true);
3435 put_door(dest,64,left,doortype[left],x,y,true,scr);
3436 break;
3437 }
3438 }
3439 else if((c&0x0F)==15)
3440 {
3441 switch(layer->door[right])
3442 {
3443 case dBOMB:
3444 case dOPEN:
3445 case dLOCKED:
3446 case d1WAYSHUTTER:
3447 case dSHUTTER:
3448 case dBOSS:
3449 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3450 break;
3451 }
3452 }
3453
3454 for(int32_t k=2; k<4; k++)
3455 {
3456 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3457 {
3458 layermap=layer->layermap[k]-1;
3459
3460 if(layermap>-1 && layermap<map_count)
3461 {
3462 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3463
3464 for(int32_t i=c; i<176; i+=16)
3465 {
3466 auto data = TheMaps[layerscreen].data[i];
3467 auto cs = TheMaps[layerscreen].cset[i];
3468 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3469 }
3470 }
3471 }
3472 }
3473
3474 //Overhead L0
3475 if(LayerMaskInt[0]!=0)
3476 {
3477 for(int32_t i=c; i<176; i+=16)
3478 {
3479 auto data = TheMaps[layerscreen].data[i];
3480 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3481 auto cs = TheMaps[layerscreen].cset[i];
3482 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3483 }
3484 }
3485 //Overhead L1/2
3486 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3487 {
3488 for(int32_t k = 0; k < 2; ++k)
3489 {
3490 if(LayerMaskInt[k+1]!=0)
3491 {
3492 layermap=layer->layermap[k]-1;
3493
3494 if(layermap>-1 && layermap<map_count)
3495 {
3496 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3497 for(int32_t i=c; i<176; i+=16)
3498 {
3499 auto data = TheMaps[layerscreen].data[i];
3500 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3501 auto cs = TheMaps[layerscreen].cset[i];
3502 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3503 }
3504 }
3505 }
3506 }
3507 }
3508
3509
3510 for(int32_t k=4; k<6; k++)
3511 {
3512 if(LayerMaskInt[k+1]!=0)
3513 {
3514 layermap=layer->layermap[k]-1;
3515
3516 if(layermap>-1 && layermap<map_count)
3517 {
3518 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3519
3520 for(int32_t i=c; i<176; i+=16)
3521 {
3522 auto data = TheMaps[layerscreen].data[i];
3523 auto cs = TheMaps[layerscreen].cset[i];
3524 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3525 }
3526 }
3527 }
3528 }
3529
3530 if(flags&cWALK)
3531 {
3532 if(LayerMaskInt[0]!=0)
3533 {
3534 for(int32_t i=c&0xF; i<176; i+=16)
3535 {
3536 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3537 }
3538 }
3539
3540 for(int32_t k=0; k<2; k++)
3541 {
3542 if(LayerMaskInt[k+1]!=0)
3543 {
3544 for(int32_t i=c&0xF; i<176; i+=16)
3545 {
3546 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3547 }
3548 }
3549 }
3550 }
3551
3552 if(flags&cFLAGS)
3553 {
3554 if(LayerMaskInt[CurrentLayer]!=0)
3555 {
3556 for(int32_t i=c; i<176; i+=16)
3557 {
3558 if(CurrentLayer==0)
3559 {
3560 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3561 }
3562 else
3563 {
3564 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3565
3566 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3567 {
3568 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3569 TheMaps[_lscr].data[i],
3570 TheMaps[_lscr].cset[i], flags|dark,
3571 TheMaps[_lscr].sflag[i]);
3572 }
3573 }
3574 }
3575 }
3576 }
3577
3578 if(ShowMisalignments)
3579 {
3580 if((c&0x0F)==0)
3581 {
3582 check_alignments(dest,x,y,scr);
3583 }
3584 else if((c&0x0F)==15)
3585 {
3586 check_alignments(dest,x-240,y,scr);
3587 }
3588 }
3589
3590 resize_mouse_pos=false;
3591 }
3592
3593 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3594 {
3595 if(map<0)
3596 map=currmap;
3597
3598 if(scr<0)
3599 scr=currscr;
3600
3601 mapscr* layer=AbsoluteScr(map,scr);
3602 int32_t layermap=0, layerscreen=0;
3603
3604 if(!(layer->valid&mVALID))
3605 {
3606 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3607 rectfill(dest,x,y,x+15,y+15,vc(1));
3608 return;
3609 }
3610
3611 int32_t dark = layer->flags&4;
3612
3613 resize_mouse_pos=true;
3614
3615 if(LayerMaskInt[0]!=0)
3616 {
3617 rectfill(dest,x,y,x+15,y+15,0);
3618 }
3619
3620 for(int32_t k=1; k<3; k++)
3621 {
3622 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3623 {
3624 layermap=layer->layermap[k]-1;
3625
3626 if(layermap>-1 && layermap<map_count)
3627 {
3628 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3629
3630 auto data = TheMaps[layerscreen].data[c];
3631 auto cs = TheMaps[layerscreen].cset[c];
3632 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3633 }
3634 }
3635 }
3636
3637 if(LayerMaskInt[0]!=0)
3638 {
3639 word cmbdat = layer->data[c];
3640 byte cmbcset = layer->cset[c];
3641 int32_t cmbflag = layer->sflag[c];
3642 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3643 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3644 }
3645
3646
3647 for(int32_t k=0; k<2; k++)
3648 {
3649 if(LayerMaskInt[k+1]!=0)
3650 {
3651 layermap=layer->layermap[k]-1;
3652
3653 if(layermap>-1 && layermap<map_count)
3654 {
3655 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3656
3657 auto data = TheMaps[layerscreen].data[c];
3658 auto cs = TheMaps[layerscreen].cset[c];
3659 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3660 }
3661 }
3662 }
3663
3664 for(int32_t k=2; k<4; k++)
3665 {
3666 if(LayerMaskInt[k+1]!=0)
3667 {
3668 layermap=layer->layermap[k]-1;
3669
3670 if(layermap>-1 && layermap<map_count)
3671 {
3672 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3673 auto data = TheMaps[layerscreen].data[c];
3674 auto cs = TheMaps[layerscreen].cset[c];
3675 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3676 }
3677 }
3678 }
3679
3680 //Overhead L0
3681 if(LayerMaskInt[0]!=0)
3682 {
3683 auto data = TheMaps[layerscreen].data[c];
3684 if(combo_class_buf[combobuf[data].type].overhead)
3685 {
3686 auto cs = TheMaps[layerscreen].cset[c];
3687 drawcombo(dest,x,y,data,cs,0,0);
3688 }
3689 }
3690 //Overhead L1/2
3691 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3692 {
3693 for(int32_t k = 0; k < 2; ++k)
3694 {
3695 if(LayerMaskInt[k+1]!=0)
3696 {
3697 layermap=layer->layermap[k]-1;
3698
3699 if(layermap>-1 && layermap<map_count)
3700 {
3701 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3702 auto data = TheMaps[layerscreen].data[c];
3703 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3704 auto cs = TheMaps[layerscreen].cset[c];
3705 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3706 }
3707 }
3708 }
3709 }
3710
3711
3712 for(int32_t k=4; k<6; k++)
3713 {
3714 if(LayerMaskInt[k+1]!=0)
3715 {
3716 layermap=layer->layermap[k]-1;
3717
3718 if(layermap>-1 && layermap<map_count)
3719 {
3720 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3721 auto data = TheMaps[layerscreen].data[c];
3722 auto cs = TheMaps[layerscreen].cset[c];
3723 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3724 }
3725 }
3726 }
3727
3728 if(flags&cWALK)
3729 {
3730 if(LayerMaskInt[0]!=0)
3731 {
3732 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3733 }
3734
3735 for(int32_t k=0; k<2; k++)
3736 {
3737 if(LayerMaskInt[k+1]!=0)
3738 {
3739 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3740 }
3741 }
3742 }
3743
3744 if(flags&cFLAGS)
3745 {
3746 if(LayerMaskInt[CurrentLayer]!=0)
3747 {
3748 int32_t i = c;
3749 //for(int32_t i=c; i==c; i++)
3750 {
3751 if(CurrentLayer==0)
3752 {
3753 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3754 }
3755 else
3756 {
3757 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3758
3759 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3760 {
3761 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3762 TheMaps[_lscr].data[i],
3763 TheMaps[_lscr].cset[i], flags|dark,
3764 TheMaps[_lscr].sflag[i]);
3765 }
3766 }
3767 }
3768 }
3769 }
3770
3771 if(ShowMisalignments)
3772 {
3773 switch(c)
3774 {
3775 case 0:
3776 check_alignments(dest,x,y,scr);
3777 break;
3778
3779 case 15:
3780 check_alignments(dest,x-240,y,scr);
3781 break;
3782
3783 case 160:
3784 check_alignments(dest,x,y-160,scr);
3785 break;
3786
3787 case 175:
3788 check_alignments(dest,x-240,y-160,scr);
3789 break;
3790 }
3791 }
3792
3793 resize_mouse_pos=false;
3794
3795 }
3796
3797 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3798 {
3799 if (InvalidBG == 2)
3800 {
3801 draw_checkerboard(dest, x, y, 16);
3802 }
3803 else if(InvalidBG == 1)
3804 {
3805 for(int32_t dy=0; dy<16; dy++)
3806 {
3807 for(int32_t dx=0; dx<16; dx++)
3808 {
3809 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3810 }
3811 }
3812 }
3813 else
3814 {
3815 rectfill(dest, x, y, x+15, y+15, vc(0));
3816 rect(dest, x, y, x+15, y+15, vc(15));
3817 line(dest, x, y, x+15, y+15, vc(15));
3818 line(dest, x, y+15, x+15, y, vc(15));
3819 }
3820 }
3821
3822 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3823 {
3824 if (InvalidBG == 2)
3825 {
3826 for(int32_t q = 0; q < 11; ++q)
3827 draw_checkerboard(dest, x, y + q * 16, 16);
3828 }
3829 else if(InvalidBG == 1)
3830 {
3831 for(int32_t dy=0; dy<176; dy++)
3832 {
3833 for(int32_t dx=0; dx<16; dx++)
3834 {
3835 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3836 }
3837 }
3838 }
3839 else
3840 {
3841 rectfill(dest, x, y, x+15, y+175, vc(0));
3842 rect(dest, x, y, x+15, y+175, vc(15));
3843 line(dest, x, y, x+15, y+175, vc(15));
3844 line(dest, x, y+175, x+15, y, vc(15));
3845 }
3846 }
3847
3848 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3849 {
3850 if (InvalidBG == 2)
3851 {
3852 for (int32_t q = 0; q < 16; ++q)
3853 draw_checkerboard(dest, x + q * 16, y, 16);
3854 }
3855 else if(InvalidBG == 1)
3856 {
3857 for(int32_t dy=0; dy<16; dy++)
3858 {
3859 for(int32_t dx=0; dx<256; dx++)
3860 {
3861 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3862 }
3863 }
3864 }
3865 else
3866 {
3867 rectfill(dest, x, y, x+255, y+15, vc(0));
3868 rect(dest, x, y, x+255, y+15, vc(15));
3869 line(dest, x, y, x+255, y+15, vc(15));
3870 line(dest, x, y+15, x+255, y, vc(15));
3871 }
3872 }
3873
3874 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3875 {
3876 for(int32_t i=0; i<176; i++)
3877 {
3878 word cmbdat = screens[TEMPLATE].data[i];
3879 byte cmbcset = screens[TEMPLATE].cset[i];
3880 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3881 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3882 }
3883 }
3884
3885 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3886 {
3887 for(int32_t i=0; i<176; i++)
3888 {
3889 word cmbdat = screens[TEMPLATE2].data[i];
3890 byte cmbcset = screens[TEMPLATE2].cset[i];
3891 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3892 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3893 }
3894 }
3895
3896 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3897 {
3898 word cmbdat = screens[TEMPLATE].data[pos];
3899 byte cmbcset = screens[TEMPLATE].cset[pos];
3900 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3901 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3902 }
3903
3904 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3905 {
3906 word cmbdat = screens[currscr].secretcombo[scombo];
3907 byte cmbcset = screens[currscr].secretcset[scombo];
3908 byte cmbflag = screens[currscr].secretflag[scombo];
3909 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3910 }
3911
3912 void zmap::scroll(int32_t dir, bool warp)
3913 {
3914 if(currmap<map_count)
3915 {
3916 switch(dir)
3917 {
3918 case up:
3919 if(warp && Map.CurrScr()->flags2&wfUP)
3920 {
3921 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3922 }
3923 else if(currscr>15)
3924 {
3925 setCurrScr(currscr-16);
3926 }
3927
3928 break;
3929
3930 case down:
3931 if(warp && Map.CurrScr()->flags2&wfDOWN)
3932 {
3933 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3934 }
3935 else if(currscr<MAPSCRS-16)
3936 {
3937 setCurrScr(currscr+16);
3938 }
3939
3940 break;
3941
3942 case left:
3943 if(warp && Map.CurrScr()->flags2&wfLEFT)
3944 {
3945 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3946 }
3947 else if(currscr&15)
3948 {
3949 setCurrScr(currscr-1);
3950 }
3951
3952 break;
3953
3954 case right:
3955 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3956 {
3957 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3958 }
3959 else if((currscr&15)<15 && currscr<MAPSCRS-1)
3960 {
3961 setCurrScr(currscr+1);
3962 }
3963
3964 break;
3965 }
3966 }
3967 }
3968
3969 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3970 {
3971 switch(side)
3972 {
3973 case up:
3974 switch(door)
3975 {
3976 case dWALL:
3977 case dBOMB:
3978 case dWALK:
3979 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3980 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3981 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3982 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3983 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3984 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3985 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3986 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3987 break;
3988
3989 default:
3990 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3991 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3992 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3993 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3994 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3995 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3996 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3997 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3998 break;
3999 }
4000
4001 break;
4002
4003 case down:
4004 switch(door)
4005 {
4006 case dWALL:
4007 case dBOMB:
4008 case dWALK:
4009 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4010 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4011 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4012 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4013 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4014 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4015 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4016 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4017 break;
4018
4019 default:
4020 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4021 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4022 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4023 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4024 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4025 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4026 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4027 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4028 break;
4029 }
4030
4031 break;
4032
4033 case left:
4034 switch(door)
4035 {
4036 case dWALL:
4037 case dBOMB:
4038 case dWALK:
4039 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4040 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4041 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4042 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4043 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4044 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4045 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4046 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4047 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4048 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4049 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4050 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4051 break;
4052
4053 default:
4054 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4055 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4056 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4057 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4058 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4059 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4060 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4061 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4062 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4063 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4064 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4065 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4066 break;
4067 }
4068
4069 break;
4070
4071 case right:
4072 switch(door)
4073 {
4074 case dWALL:
4075 case dBOMB:
4076 case dWALK:
4077 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4078 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4079 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4080 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4081 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4082 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4083 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4084 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4085 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4086 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4087 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4088 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4089 break;
4090
4091 default:
4092 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4093 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4094 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4095 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4096 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4097 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4098 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4099 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4100 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4101 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4102 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4103 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4104 break;
4105 }
4106
4107 break;
4108 }
4109 }
4110 void zmap::DoPutDoorCommand(int side, int door, bool force)
4111 {
4112 if(!force && screens[currscr].door[side] == door)
4113 return;
4114 bool already_list = InListCommand();
4115 if(!already_list)
4116 StartListCommand();
4117 DoSetDoorCommand(currscr,side,door);
4118 if(door != dNONE)
4119 {
4120 word data[176] = {0};
4121 byte cset[176] = {0};
4122 fetch_door(side, door, screens[currscr].door_combo_set, data, cset);
4123 for(int q = 0; q < 176; ++q)
4124 if(data[q])
4125 DoSetComboCommand(currmap,currscr,q,data[q],cset[q]);
4126 }
4127 if(!already_list)
4128 FinishListCommand();
4129 }
4130 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4131 {
4132 if(screens[scr].door[side] == door)
4133 return;
4134 screens[scr].door[side] = door;
4135 if(door != dNONE)
4136 {
4137 word data[176] = {0};
4138 byte cset[176] = {0};
4139 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4140 for(int q = 0; q < 176; ++q)
4141 if(data[q])
4142 {
4143 screens[scr].data[q] = data[q];
4144 screens[scr].cset[q] = cset[q];
4145 }
4146 }
4147 }
4148
4149 void list_command::execute()
4150 {
4151 for (auto command : commands)
4152 {
4153 command->execute();
4154 }
4155 }
4156
4157 void list_command::undo()
4158 {
4159 for (int i = commands.size() - 1; i >= 0; i--)
4160 {
4161 commands[i]->undo();
4162 }
4163 }
4164
4165 int list_command::size()
4166 {
4167 int s = 0;
4168 for (auto command : commands)
4169 {
4170 s += command->size();
4171 }
4172 return s;
4173 }
4174
4175 void set_combo_command::execute()
4176 {
4177 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4178 if(!mapscr_ptr) return;
4179
4180 mapscr_ptr->valid |= mVALID;
4181 if (combo != -1) mapscr_ptr->data[pos] = combo;
4182 mapscr_ptr->cset[pos] = cset;
4183 }
4184
4185 void set_combo_command::undo()
4186 {
4187 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4188 if(!mapscr_ptr) return;
4189 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4190 mapscr_ptr->cset[pos] = prev_cset;
4191 }
4192
4193 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4194 {
4195 std::array<int, 2> inita_arr;
4196 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4197 std::array<int, 8> initd_arr;
4198 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4199
4200 return {
4201 .x = ffc.x,
4202 .y = ffc.y,
4203 .vx = ffc.vx,
4204 .vy = ffc.vy,
4205 .ax = ffc.ax,
4206 .ay = ffc.ay,
4207 .data = ffc.data,
4208 .cset = ffc.cset,
4209 .delay = ffc.delay,
4210 .link = ffc.link,
4211 .script = ffc.script,
4212 .tw = ffc.txsz,
4213 .th = ffc.tysz,
4214 .ew = ffc.hit_width,
4215 .eh = ffc.hit_height,
4216 .flags = ffc.flags,
4217 .inita = inita_arr,
4218 .initd = initd_arr,
4219 };
4220 }
4221
4222 void set_ffc_command::execute()
4223 {
4224 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4225 if(!mapscr_ptr) return;
4226
4227 mapscr_ptr->valid |= mVALID;
4228 mapscr_ptr->ffcs[i].x = data.x;
4229 mapscr_ptr->ffcs[i].y = data.y;
4230 mapscr_ptr->ffcs[i].vx = data.vx;
4231 mapscr_ptr->ffcs[i].vy = data.vy;
4232 mapscr_ptr->ffcs[i].ax = data.ax;
4233 mapscr_ptr->ffcs[i].ay = data.ay;
4234 mapscr_ptr->ffcs[i].data = data.data;
4235 mapscr_ptr->ffcs[i].cset = data.cset;
4236 mapscr_ptr->ffcs[i].delay = data.delay;
4237 mapscr_ptr->ffcs[i].link = data.link;
4238 mapscr_ptr->ffcs[i].script = data.script;
4239 mapscr_ptr->ffcs[i].flags = data.flags;
4240 mapscr_ptr->ffEffectWidth(i, data.ew);
4241 mapscr_ptr->ffEffectHeight(i, data.eh);
4242 mapscr_ptr->ffTileWidth(i, data.tw);
4243 mapscr_ptr->ffTileHeight(i, data.th);
4244 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4245 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4246 mapscr_ptr->ffcCountMarkDirty();
4247 mapscr_ptr->ffcs[i].updateSolid();
4248 }
4249
4250 void set_ffc_command::undo()
4251 {
4252 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4253 if(!mapscr_ptr) return;
4254
4255 mapscr_ptr->ffcs[i].x = prev_data.x;
4256 mapscr_ptr->ffcs[i].y = prev_data.y;
4257 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4258 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4259 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4260 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4261 mapscr_ptr->ffcs[i].data = prev_data.data;
4262 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4263 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4264 mapscr_ptr->ffcs[i].link = prev_data.link;
4265 mapscr_ptr->ffcs[i].script = prev_data.script;
4266 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4267 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4268 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4269 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4270 mapscr_ptr->ffTileHeight(i, prev_data.th);
4271 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4272 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4273 mapscr_ptr->ffcCountMarkDirty();
4274 mapscr_ptr->ffcs[i].updateSolid();
4275 }
4276
4277 void set_flag_command::execute()
4278 {
4279 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4280 if(!mapscr_ptr) return;
4281
4282 mapscr_ptr->valid |= mVALID;
4283 mapscr_ptr->sflag[pos] = flag;
4284 }
4285
4286 void set_flag_command::undo()
4287 {
4288 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4289 if(!mapscr_ptr) return;
4290 mapscr_ptr->sflag[pos] = prev_flag;
4291 }
4292
4293 void set_door_command::execute()
4294 {
4295 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4296 if(!mapscr_ptr) return;
4297
4298 mapscr_ptr->valid |= mVALID;
4299 mapscr_ptr->door[side] = door;
4300 }
4301
4302 void set_door_command::undo()
4303 {
4304 Map.AbsoluteScr(view_map, view_scr)->door[side] = prev_door;
4305 }
4306
4307 void set_dcs_command::execute()
4308 {
4309 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4310 if(!mapscr_ptr) return;
4311
4312 mapscr_ptr->valid |= mVALID;
4313 mapscr_ptr->door_combo_set = dcs;
4314 }
4315
4316 void set_dcs_command::undo()
4317 {
4318 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = prev_dcs;
4319 }
4320
4321 void paste_screen_command::execute()
4322 {
4323 perform(screen.get());
4324 }
4325
4326 void paste_screen_command::undo()
4327 {
4328 if (prev_screens.size() > 1)
4329 {
4330 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4331 ASSERT(prev_screens.size() == 128);
4332 for (int i = 0; i < 128; i++)
4333 {
4334 copy_mapscr(Map.AbsoluteScr(view_map, i), prev_screens[i].get());
4335 // TODO: why not just this?
4336 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4337 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4338 }
4339 return;
4340 }
4341
4342 perform(prev_screens[0].get());
4343 }
4344
4345 int paste_screen_command::size()
4346 {
4347 return prev_screens.size() + 1;
4348 }
4349
4350 void paste_screen_command::perform(mapscr* to)
4351 {
4352 if (to)
4353 {
4354 switch (type) {
4355 case ScreenAll: Map.PasteAll(*to); break;
4356 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4357 case ScreenData: Map.PasteScreenData(*to); break;
4358 case ScreenDoors: Map.PasteDoors(*to); break;
4359 case ScreenEnemies: Map.PasteEnemies(*to); break;
4360 case ScreenFFCombos: Map.PasteFFCombos(*to); break;
4361 case ScreenGuy: Map.PasteGuy(*to); break;
4362 case ScreenLayers: Map.PasteLayers(*to); break;
4363 case ScreenPalette: Map.PastePalette(*to); break;
4364 case ScreenPartial: Map.Paste(*to); break;
4365 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4366 case ScreenRoom: Map.PasteRoom(*to); break;
4367 case ScreenSecretCombos: Map.PasteSecretCombos(*to); break;
4368 case ScreenUnderCombo: Map.PasteUnderCombo(*to); break;
4369 case ScreenWarpLocations: Map.PasteWarpLocations(*to); break;
4370 case ScreenWarps: Map.PasteWarps(*to); break;
4371 }
4372 }
4373 else
4374 {
4375 Map.clearscr(view_scr);
4376 }
4377 refresh(rALL);
4378 }
4379
4380 void set_screen_command::execute()
4381 {
4382 if (screen)
4383 {
4384 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), screen.get());
4385 }
4386 else
4387 {
4388 Map.clearscr(view_scr);
4389 }
4390 refresh(rALL);
4391 }
4392
4393 void set_screen_command::undo()
4394 {
4395 if (prev_screen)
4396 {
4397 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), prev_screen.get());
4398 }
4399 else
4400 {
4401 Map.clearscr(view_scr);
4402 }
4403 refresh(rALL);
4404 }
4405
4406 int set_screen_command::size()
4407 {
4408 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4409 }
4410
4411 extern byte relational_tile_grid[11+(rtgyo*2)][16+(rtgxo*2)];
4412
4413 void tile_grid_draw_command::execute()
4414 {
4415 util::copy_2d_array<byte, 15, 20>(tile_grid, relational_tile_grid);
4416 }
4417
4418 void tile_grid_draw_command::undo()
4419 {
4420 util::copy_2d_array<byte, 15, 20>(prev_tile_grid, relational_tile_grid);
4421 }
4422
4423 static std::shared_ptr<list_command> current_list_command;
4424 void zmap::StartListCommand()
4425 {
4426 ASSERT(!current_list_command);
4427 current_list_command.reset(new list_command);
4428 }
4429
4430 void zmap::FinishListCommand()
4431 {
4432 if (current_list_command->commands.size() == 1)
4433 {
4434 undo_stack.push_back(current_list_command->commands[0]);
4435 }
4436 else if (current_list_command->commands.size() > 1)
4437 {
4438 undo_stack.push_back(current_list_command);
4439 }
4440 CapCommandHistory();
4441 current_list_command = nullptr;
4442 }
4443
4444 void zmap::RevokeListCommand()
4445 {
4446 current_list_command->undo();
4447 current_list_command = nullptr;
4448 }
4449
4450 bool zmap::InListCommand() const
4451 {
4452 return current_list_command ? true : false;
4453 }
4454
4455 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4456 {
4457 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4458 if (!skip_execute) command->execute();
4459 if (current_list_command)
4460 {
4461 current_list_command->commands.push_back(command);
4462 if (current_list_command->commands.size() == 1)
4463 {
4464 current_list_command->view_map = command->view_map;
4465 current_list_command->view_scr = command->view_scr;
4466 }
4467 }
4468 else
4469 {
4470 undo_stack.push_back(command);
4471 CapCommandHistory();
4472 }
4473 saved = false;
4474 }
4475
4476 void zmap::UndoCommand()
4477 {
4478 if (undo_stack.size() <= 0) return;
4479
4480 // If not currently looking at the associated screen, first change the view
4481 // and wait for the next call to actually undo this command.
4482 auto command = undo_stack.back();
4483 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4484 {
4485 setCurrentView(command->view_map, command->view_scr);
4486 return;
4487 }
4488
4489 command->undo();
4490 redo_stack.push(command);
4491 undo_stack.pop_back();
4492 saved = false;
4493 }
4494
4495 void zmap::RedoCommand()
4496 {
4497 if (redo_stack.size() <= 0) return;
4498
4499 // If not currently looking at the associated screen, first change the view
4500 // and wait for the next call to actually execute this command.
4501 auto command = redo_stack.top();
4502 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4503 {
4504 setCurrentView(command->view_map, command->view_scr);
4505 return;
4506 }
4507
4508 command->execute();
4509 undo_stack.push_back(command);
4510 redo_stack.pop();
4511 saved = false;
4512 }
4513
4514 9 void zmap::ClearCommandHistory()
4515 {
4516 9 current_list_command = nullptr;
4517 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4518 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4519 9 }
4520
4521 // Extra amount is from mapscr's vectors.
4522 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4523 // Allow the undo system to use roughly 100 MB of memory.
4524 // This doesn't count the memory used by commands that don't store a mapscr,
4525 // but that should be negligible.
4526 9 static int max_command_size = 100e6 / size_of_mapscr;
4527 void zmap::CapCommandHistory()
4528 {
4529 int size;
4530 do
4531 {
4532 size = 0;
4533 for (auto command : undo_stack)
4534 {
4535 size += command->size();
4536 }
4537 if (size > max_command_size) undo_stack.pop_front();
4538 } while (size > max_command_size);
4539 }
4540
4541 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4542 {
4543 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4544 if(!mapscr_ptr) return;
4545 std::shared_ptr<set_combo_command> command(new set_combo_command);
4546 command->view_map = currmap;
4547 command->view_scr = currscr;
4548 command->map = map;
4549 command->scr = scr;
4550 command->pos = pos;
4551 command->combo = combo;
4552 command->cset = cset;
4553 command->prev_combo = mapscr_ptr->data[pos];
4554 command->prev_cset = mapscr_ptr->cset[pos];
4555 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4556 {
4557 // nothing to do...
4558 return;
4559 }
4560
4561 ExecuteCommand(command);
4562 }
4563
4564 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4565 {
4566 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4567 if(!mapscr_ptr) return;
4568
4569 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4570
4571 std::array<int, 2> inita_arr;
4572 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4573 std::array<int, 8> initd_arr;
4574 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4575
4576 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4577
4578 command->view_map = currmap;
4579 command->view_scr = currscr;
4580 command->map = map;
4581 command->scr = scr;
4582 command->i = i;
4583 command->data = data;
4584 command->prev_data = prev_data;
4585 if (data == prev_data)
4586 {
4587 // nothing to do...
4588 return;
4589 }
4590
4591 ExecuteCommand(command);
4592 }
4593
4594 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4595 {
4596 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4597 if(!mapscr_ptr) return;
4598 std::shared_ptr<set_flag_command> command(new set_flag_command);
4599 command->view_map = currmap;
4600 command->view_scr = currscr;
4601 command->map = map;
4602 command->scr = scr;
4603 command->pos = pos;
4604 command->flag = flag;
4605 command->prev_flag = mapscr_ptr->sflag[pos];
4606 if (command->flag == command->prev_flag)
4607 {
4608 // nothing to do...
4609 return;
4610 }
4611
4612 ExecuteCommand(command);
4613 }
4614
4615 void zmap::DoSetDoorCommand(int scr, int side, int door)
4616 {
4617 if(screens[scr].door[side] == door)
4618 return;
4619 std::shared_ptr<set_door_command> command(new set_door_command);
4620 command->view_map = currmap;
4621 command->view_scr = scr;
4622 command->side = side;
4623 command->door = door;
4624 command->prev_door = screens[scr].door[side];
4625
4626 ExecuteCommand(command);
4627 }
4628 void zmap::DoSetDCSCommand(int dcs)
4629 {
4630 if(screens[currscr].door_combo_set == dcs)
4631 return;
4632 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4633 command->view_map = currmap;
4634 command->view_scr = currscr;
4635 command->dcs = dcs;
4636 command->prev_dcs = screens[currscr].door_combo_set;
4637
4638 ExecuteCommand(command);
4639 }
4640
4641 void zmap::DoPasteScreenCommand(PasteCommandType type, int data)
4642 {
4643 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4644 command->view_map = currmap;
4645 command->view_scr = currscr;
4646 command->type = type;
4647 command->data = data;
4648 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4649
4650 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4651 {
4652 for (int i=0; i < 128; i++)
4653 {
4654 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4655 }
4656 }
4657 else
4658 {
4659 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[currscr])));
4660 }
4661
4662 ExecuteCommand(command);
4663 }
4664
4665 void zmap::DoClearScreenCommand()
4666 {
4667 std::shared_ptr<set_screen_command> command(new set_screen_command);
4668 command->view_map = currmap;
4669 command->view_scr = currscr;
4670 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[currscr]));
4671 command->screen = std::shared_ptr<mapscr>(nullptr);
4672
4673 ExecuteCommand(command);
4674 }
4675
4676 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int scr)
4677 {
4678 std::shared_ptr<set_screen_command> command(new set_screen_command);
4679 command->view_map = currmap;
4680 command->view_scr = currscr;
4681 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4682 Template(floorcombo, floorcset, scr);
4683 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4684
4685 ExecuteCommand(command, true);
4686 }
4687
4688 void zmap::Copy()
4689 {
4690 if(screens[currscr].valid&mVALID)
4691 {
4692 copy_mapscr(&copymapscr, &screens[currscr]);
4693 //copymapscr=screens[currscr];
4694 can_paste=true;
4695 copymap=currmap;
4696 copyscr=currscr;
4697 copyscrdata = zinit.screen_data[currmap*MAPSCRS+currscr];
4698 copyffc = -1;
4699 }
4700 }
4701
4702 void zmap::CopyFFC(int32_t n)
4703 {
4704 if(screens[currscr].valid&mVALID)
4705 {
4706 copy_mapscr(&copymapscr, &screens[currscr]);
4707 // Can't paste the screen itself
4708 can_paste = false;
4709 copymap=currmap;
4710 copyscr=currscr;
4711 copyffc = n;
4712 }
4713 }
4714
4715 void zmap::Paste(const mapscr& copymapscr)
4716 {
4717 if(can_paste)
4718 {
4719 int32_t oldcolor=getcolor();
4720
4721 if(!(screens[currscr].valid&mVALID))
4722 {
4723 screens[currscr].valid |= mVALID;
4724 screens[currscr].color = copymapscr.color;
4725 }
4726
4727 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4728
4729 for(int32_t i=0; i<4; i++)
4730 {
4731 screens[currscr].door[i]=copymapscr.door[i];
4732 }
4733
4734 for(int32_t i=0; i<176; i++)
4735 {
4736 screens[currscr].data[i] = copymapscr.data[i];
4737 screens[currscr].cset[i] = copymapscr.cset[i];
4738 screens[currscr].sflag[i] = copymapscr.sflag[i];
4739 }
4740
4741 int32_t newcolor=getcolor();
4742 loadlvlpal(newcolor);
4743
4744 if(newcolor!=oldcolor)
4745 {
4746 rebuild_trans_table();
4747 }
4748
4749 saved=false;
4750 }
4751 }
4752
4753 void zmap::PasteUnderCombo(const mapscr& copymapscr)
4754 {
4755 if(can_paste)
4756 {
4757 screens[currscr].undercombo = copymapscr.undercombo;
4758 screens[currscr].undercset = copymapscr.undercset;
4759 saved=false;
4760 }
4761 }
4762
4763 void zmap::PasteSecretCombos(const mapscr& copymapscr)
4764 {
4765 if(can_paste)
4766 {
4767 for(int32_t i=0; i<128; i++)
4768 {
4769 screens[currscr].secretcombo[i] = copymapscr.secretcombo[i];
4770 screens[currscr].secretcset[i] = copymapscr.secretcset[i];
4771 screens[currscr].secretflag[i] = copymapscr.secretflag[i];
4772 }
4773
4774 saved=false;
4775 }
4776 }
4777
4778 // TODO const mapscr& copymapscr
4779 void zmap::PasteFFCombos(mapscr& copymapscr)
4780 {
4781 if(can_paste)
4782 {
4783 word c = copymapscr.numFFC();
4784 for(word i=0; i<c; i++)
4785 screens[currscr].ffcs[i] = copymapscr.ffcs[i];
4786 for(word i = c; i < MAXFFCS; ++i)
4787 screens[currscr].ffcs[i].clear();
4788 screens[currscr].ffcCountMarkDirty();
4789
4790 saved=false;
4791 }
4792 }
4793
4794 void zmap::PasteWarps(const mapscr& copymapscr)
4795 {
4796 if(can_paste)
4797 {
4798 screens[currscr].sidewarpindex = copymapscr.sidewarpindex;
4799
4800 for(int32_t i=0; i<4; i++)
4801 {
4802 screens[currscr].tilewarptype[i] = copymapscr.tilewarptype[i];
4803 screens[currscr].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4804 screens[currscr].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4805 screens[currscr].sidewarptype[i] = copymapscr.sidewarptype[i];
4806 screens[currscr].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4807 screens[currscr].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4808 screens[currscr].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4809 screens[currscr].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4810 screens[currscr].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4811 screens[currscr].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4812 }
4813
4814 saved=false;
4815 }
4816 }
4817
4818 void zmap::PasteScreenData(const mapscr& copymapscr)
4819 {
4820 if(can_paste)
4821 {
4822 screens[currscr].csensitive = copymapscr.csensitive;
4823 screens[currscr].oceansfx = copymapscr.oceansfx;
4824 screens[currscr].bosssfx = copymapscr.bosssfx;
4825 screens[currscr].secretsfx = copymapscr.secretsfx;
4826 screens[currscr].holdupsfx = copymapscr.holdupsfx;
4827 screens[currscr].flags = copymapscr.flags;
4828 screens[currscr].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4829 screens[currscr].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4830 screens[currscr].flags3 = copymapscr.flags3;
4831 screens[currscr].flags4 = copymapscr.flags4;
4832 screens[currscr].flags5 = copymapscr.flags5;
4833 screens[currscr].flags6 = copymapscr.flags6;
4834 screens[currscr].flags7 = copymapscr.flags7;
4835 screens[currscr].flags8 = copymapscr.flags8;
4836 screens[currscr].flags9 = copymapscr.flags9;
4837 screens[currscr].flags10 = copymapscr.flags10;
4838 screens[currscr].item = copymapscr.item;
4839 screens[currscr].hasitem = copymapscr.hasitem;
4840 screens[currscr].itemx = copymapscr.itemx;
4841 screens[currscr].itemy = copymapscr.itemy;
4842 screens[currscr].nextmap = copymapscr.nextmap;
4843 screens[currscr].nextscr = copymapscr.nextscr;
4844 screens[currscr].nocarry = copymapscr.nocarry;
4845 screens[currscr].noreset = copymapscr.noreset;
4846 screens[currscr].path[0] = copymapscr.path[0];
4847 screens[currscr].path[1] = copymapscr.path[1];
4848 screens[currscr].path[2] = copymapscr.path[2];
4849 screens[currscr].path[3] = copymapscr.path[3];
4850 screens[currscr].pattern = copymapscr.pattern;
4851 screens[currscr].exitdir = copymapscr.exitdir;
4852 screens[currscr].enemyflags = copymapscr.enemyflags;
4853 screens[currscr].screen_midi = copymapscr.screen_midi;
4854 screens[currscr].stairx = copymapscr.stairx;
4855 screens[currscr].stairy = copymapscr.stairy;
4856 screens[currscr].timedwarptics = copymapscr.timedwarptics;
4857 saved=false;
4858 }
4859 }
4860
4861 void zmap::PasteWarpLocations(const mapscr& copymapscr)
4862 {
4863 if(can_paste)
4864 {
4865 screens[currscr].warpreturnc = copymapscr.warpreturnc;
4866 screens[currscr].warparrivalx = copymapscr.warparrivalx;
4867 screens[currscr].warparrivaly = copymapscr.warparrivaly;
4868
4869 for(int32_t i=0; i<4; i++)
4870 {
4871 screens[currscr].warpreturnx[i] = copymapscr.warpreturnx[i];
4872 screens[currscr].warpreturny[i] = copymapscr.warpreturny[i];
4873 }
4874
4875 saved=false;
4876 }
4877 }
4878
4879 void zmap::PasteDoors(const mapscr& copymapscr)
4880 {
4881 if(can_paste)
4882 {
4883 for(int32_t i=0; i<4; i++)
4884 screens[currscr].door[i] = copymapscr.door[i];
4885
4886 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4887 saved=false;
4888 }
4889 }
4890
4891 void zmap::PasteLayers(const mapscr& copymapscr)
4892 {
4893 if(can_paste)
4894 {
4895 for(int32_t i=0; i<6; i++)
4896 {
4897 screens[currscr].layermap[i] = copymapscr.layermap[i];
4898 screens[currscr].layerscreen[i] = copymapscr.layerscreen[i];
4899 screens[currscr].layeropacity[i] = copymapscr.layeropacity[i];
4900 }
4901
4902 saved=false;
4903 }
4904 }
4905
4906 void zmap::PasteRoom(const mapscr& copymapscr)
4907 {
4908 if(can_paste)
4909 {
4910 screens[currscr].room = copymapscr.room;
4911 screens[currscr].catchall = copymapscr.catchall;
4912 saved=false;
4913 }
4914 }
4915
4916 void zmap::PasteGuy(const mapscr& copymapscr)
4917 {
4918 if(can_paste)
4919 {
4920 screens[currscr].guy = copymapscr.guy;
4921 screens[currscr].guytile = copymapscr.guytile;
4922 screens[currscr].guycs = copymapscr.guycs;
4923 SETFLAG(screens[currscr].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4924 SETFLAG(screens[currscr].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4925 screens[currscr].str = copymapscr.str;
4926 saved=false;
4927 }
4928 }
4929
4930 void zmap::PastePalette(const mapscr& copymapscr)
4931 {
4932 if(can_paste)
4933 {
4934 int32_t oldcolor=getcolor();
4935 screens[currscr].color = copymapscr.color;
4936 int32_t newcolor=getcolor();
4937 loadlvlpal(newcolor);
4938
4939 screens[currscr].valid|=mVALID;
4940
4941 if(newcolor!=oldcolor)
4942 {
4943 rebuild_trans_table();
4944 }
4945
4946 saved=false;
4947 }
4948 }
4949
4950 void zmap::PasteAll(const mapscr& copymapscr)
4951 {
4952 if(can_paste)
4953 {
4954 int32_t oldcolor=getcolor();
4955 copy_mapscr(&screens[currscr], &copymapscr);
4956 zinit.screen_data[currmap*MAPSCRS+currscr] = copyscrdata;
4957 //screens[currscr]=copymapscr;
4958 int32_t newcolor=getcolor();
4959 loadlvlpal(newcolor);
4960
4961 screens[currscr].valid|=mVALID;
4962
4963 if(newcolor!=oldcolor)
4964 {
4965 rebuild_trans_table();
4966 }
4967
4968 saved=false;
4969 }
4970 }
4971
4972
4973 void zmap::PasteToAll(const mapscr& copymapscr)
4974 {
4975 if(can_paste)
4976 {
4977 int32_t oldcolor=getcolor();
4978
4979 for(int32_t x=0; x<128; x++)
4980 {
4981 if(!(screens[x].valid&mVALID))
4982 {
4983 screens[x].valid |= mVALID;
4984 screens[x].color = copymapscr.color;
4985 }
4986
4987 for(int32_t i=0; i<176; i++)
4988 {
4989 screens[x].data[i] = copymapscr.data[i];
4990 screens[x].cset[i] = copymapscr.cset[i];
4991 screens[x].sflag[i] = copymapscr.sflag[i];
4992 }
4993 }
4994
4995 int32_t newcolor=getcolor();
4996 loadlvlpal(newcolor);
4997
4998 if(!(screens[currscr].valid&mVALID))
4999 {
5000 newcolor=-1;
5001 }
5002
5003 if(newcolor!=oldcolor)
5004 {
5005 rebuild_trans_table();
5006 }
5007
5008 saved=false;
5009 }
5010 }
5011
5012 void zmap::PasteAllToAll(const mapscr& copymapscr)
5013 {
5014 if(can_paste)
5015 {
5016 int32_t oldcolor=getcolor();
5017
5018 for(int32_t x=0; x<128; x++)
5019 {
5020 copy_mapscr(&screens[x], &copymapscr);
5021 zinit.screen_data[currmap*MAPSCRS+x] = copyscrdata;
5022 //screens[x]=copymapscr;
5023 }
5024
5025 int32_t newcolor=getcolor();
5026 loadlvlpal(newcolor);
5027
5028 if(!(screens[currscr].valid&mVALID))
5029 {
5030 newcolor=-1;
5031 }
5032
5033 if(newcolor!=oldcolor)
5034 {
5035 rebuild_trans_table();
5036 }
5037
5038 saved=false;
5039 }
5040 }
5041
5042 void zmap::PasteEnemies(const mapscr& copymapscr)
5043 {
5044 if(can_paste)
5045 {
5046 for(int32_t i=0; i<10; i++)
5047 screens[currscr].enemy[i]=copymapscr.enemy[i];
5048 }
5049 }
5050
5051 void zmap::setCopyFFC(int32_t n)
5052 {
5053 copyffc = n;
5054 }
5055
5056 void zmap::update_combo_cycling()
5057 {
5058 if(!prv_mode||!prv_cmbcycle)
5059 {
5060 return;
5061 }
5062
5063 int32_t x;
5064 int32_t newdata[176];
5065 int32_t newcset[176];
5066 bool restartanim[MAXCOMBOS] = {0};
5067
5068 for(int32_t i=0; i<176; i++)
5069 {
5070 newdata[i]=-1;
5071 newcset[i]=-1;
5072
5073 x=prvscr.data[i];
5074
5075 //time to restart
5076 if((combobuf[x].aclk>=combobuf[x].speed) &&
5077 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5078 (combobuf[x].nextcombo!=0))
5079 {
5080 newdata[i]=combobuf[x].nextcombo;
5081 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5082 newcset[i]=combobuf[x].nextcset;
5083 int32_t c = newdata[i];
5084
5085 if(combobuf[c].animflags & AF_CYCLE)
5086 {
5087 restartanim[c]=true;
5088 }
5089 }
5090 }
5091
5092 for(int32_t i=0; i<176; i++)
5093 {
5094 x=prvscr.data[i];
5095
5096 //time to restart
5097 if((combobuf[x].aclk>=combobuf[x].speed) &&
5098 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5099 (combobuf[x].nextcombo!=0))
5100 {
5101 newdata[i]=combobuf[x].nextcombo;
5102 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5103 newcset[i]=combobuf[x].nextcset;
5104 int32_t c = newdata[i];
5105
5106 if(combobuf[c].animflags & AF_CYCLE)
5107 {
5108 restartanim[c]=true;
5109 }
5110 }
5111 }
5112
5113 for(int32_t i=0; i<176; i++)
5114 {
5115 if(newdata[i]==-1)
5116 continue;
5117
5118 prvscr.data[i]=newdata[i];
5119 prvscr.cset[i]=newcset[i];
5120 }
5121
5122 word maxffc = prvscr.numFFC();
5123 for(word i=0; i<maxffc; i++)
5124 {
5125 ffcdata& ffc = prvscr.ffcs[i];
5126 newcombo const& cmb = combobuf[ffc.data];
5127
5128 //time to restart
5129 if((cmb.aclk>=cmb.speed) &&
5130 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5131 (cmb.nextcombo!=0))
5132 {
5133 ffc.data = cmb.nextcombo;
5134 if(!(cmb.animflags & AF_CYCLENOCSET))
5135 ffc.cset=cmb.nextcset;
5136
5137 if(combobuf[ffc.data].animflags & AF_CYCLE)
5138 {
5139 restartanim[ffc.data]=true;
5140 }
5141 prvscr.ffcs[i].data = ffc.data;
5142 prvscr.ffcs[i].cset=ffc.cset;
5143 }
5144 }
5145
5146
5147 if(get_qr(qr_CMBCYCLELAYERS))
5148 {
5149 for(int32_t j=0; j<6; j++)
5150 {
5151 if(!prvlayers[j].valid)
5152 continue;
5153
5154 for(int32_t i=0; i<176; i++)
5155 {
5156 newdata[i]=-1;
5157 newcset[i]=-1;
5158
5159 x=(prvlayers[j]).data[i];
5160
5161 //time to restart
5162 if((combobuf[x].aclk>=combobuf[x].speed) &&
5163 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5164 (combobuf[x].nextcombo!=0))
5165 {
5166 newdata[i]=combobuf[x].nextcombo;
5167 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5168 newcset[i]=combobuf[x].nextcset;
5169 int32_t c = newdata[i];
5170
5171 if(combobuf[c].animflags & AF_CYCLE)
5172 {
5173 restartanim[c]=true;
5174 }
5175 }
5176 }
5177
5178 for(int32_t i=0; i<176; i++)
5179 {
5180 x=(prvlayers[j]).data[i];
5181
5182 //time to restart
5183 if((combobuf[x].aclk>=combobuf[x].speed) &&
5184 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5185 (combobuf[x].nextcombo!=0))
5186 {
5187 newdata[i]=combobuf[x].nextcombo;
5188 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5189 newcset[i]=combobuf[x].nextcset;
5190 int32_t c = newdata[i];
5191
5192 if(combobuf[c].animflags & AF_CYCLE)
5193 {
5194 restartanim[c]=true;
5195 }
5196 }
5197 }
5198
5199 for(int32_t i=0; i<176; i++)
5200 {
5201 if(newdata[i]==-1)
5202 continue;
5203
5204 prvlayers[j].data[i]=newdata[i];
5205 prvlayers[j].cset[i]=newcset[i];
5206 }
5207 }
5208 }
5209
5210 for(int32_t i=0; i<MAXCOMBOS; i++)
5211 {
5212 if(restartanim[i])
5213 {
5214 combobuf[i].tile = combobuf[i].o_tile;
5215 combobuf[i].cur_frame=0;
5216 combobuf[i].aclk = 0;
5217 }
5218 }
5219 }
5220
5221 void zmap::update_freeform_combos()
5222 {
5223 if(!prv_mode||!prv_cmbcycle)
5224 {
5225 return;
5226 }
5227
5228 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5229 word maxffc = prvscr.numFFC();
5230 for(int32_t i=0; i<maxffc; i++)
5231 {
5232 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5233 {
5234 for(int32_t j=0; j<maxffc; j++)
5235 {
5236 if(i!=j)
5237 {
5238 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5239 {
5240 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5241 {
5242 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5243 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5244 {
5245 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5246 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5247 if(prvscr.ffcs[j].flags&ffc_changethis)
5248 {
5249 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5250 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5251 }
5252
5253 if(prvscr.ffcs[j].flags&ffc_changenext)
5254 prvscr.ffcs[i].data += 1;
5255
5256 if(prvscr.ffcs[j].flags&ffc_changeprev)
5257 prvscr.ffcs[i].data -= 1;
5258
5259 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5260 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5261 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5262
5263 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5264 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5265 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5266 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5267
5268 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5269 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5270 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5271 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5272 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5273
5274 if(prvscr.ffcs[i].flags&ffc_carryover)
5275 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5276 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5277
5278 prvscr.ffcs[i].flags&=~ffc_changer;
5279 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5280 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5281
5282 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5283 {
5284 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5285 }
5286
5287 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5288 {
5289 int32_t k=0;
5290
5291 if(prvscr.ffcs[j].flags&ffc_swapnext)
5292 k=j<(MAXFFCS-1)?j+1:0;
5293
5294 if(prvscr.ffcs[j].flags&ffc_swapprev)
5295 k=j>0?j-1:(MAXFFCS-1);
5296
5297 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5298 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5299 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5300 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5301 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5302 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5303 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5304 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5305 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5306 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5307 }
5308 }
5309 }
5310 }
5311 }
5312 }
5313
5314 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5315 {
5316 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5317 {
5318 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5319 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5320 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5321 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5322 }
5323 else
5324 {
5325 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5326 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5327 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5328 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5329 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5330 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5331
5332 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5333 {
5334 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5335
5336 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5337
5338 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5339
5340 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5341 }
5342 }
5343 }
5344 else
5345 {
5346 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5347 prvscr.ffcs[i].delay--;
5348 }
5349
5350 if(prvscr.ffcs[i].x<-32)
5351 {
5352 if(prvscr.flags6&fWRAPAROUNDFF)
5353 {
5354 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5355 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5356 }
5357 else
5358 {
5359 prvscr.ffcs[i].data = 0;
5360 prvscr.ffcs[i].flags&=~ffc_carryover;
5361 }
5362 }
5363
5364 if(prvscr.ffcs[i].y<-32)
5365 {
5366 if(prvscr.flags6&fWRAPAROUNDFF)
5367 {
5368 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5369 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5370 }
5371 else
5372 {
5373 prvscr.ffcs[i].data = 0;
5374 prvscr.ffcs[i].flags&=~ffc_carryover;
5375 }
5376 }
5377
5378 if(prvscr.ffcs[i].x>=288)
5379 {
5380 if(prvscr.flags6&fWRAPAROUNDFF)
5381 {
5382 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5383 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5384 }
5385 else
5386 {
5387 prvscr.ffcs[i].data = 0;
5388 prvscr.ffcs[i].flags&=~ffc_carryover;
5389 }
5390 }
5391
5392 if(prvscr.ffcs[i].y>=208)
5393 {
5394 if(prvscr.flags6&fWRAPAROUNDFF)
5395 {
5396 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5397 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5398 }
5399 else
5400 {
5401 prvscr.ffcs[i].data = 0;
5402 prvscr.ffcs[i].flags&=~ffc_carryover;
5403 }
5404 }
5405
5406 }
5407 }
5408 }
5409
5410 void zmap::goto_dmapscr(int dmap, int scr)
5411 {
5412 setCurrMap(DMaps[dmap].map);
5413 setCurrScr(scr+DMaps[dmap].xoff);
5414 }
5415 void zmap::goto_mapscr(int map, int scr)
5416 {
5417 setCurrMap(map);
5418 setCurrScr(scr);
5419 }
5420
5421 void zmap::dowarp(int32_t type, int32_t index)
5422 {
5423 set_warpback();
5424 if(type==0)
5425 {
5426
5427 int32_t dmap=screens[currscr].tilewarpdmap[index];
5428 int32_t scr=screens[currscr].tilewarpscr[index];
5429
5430 switch(screens[currscr].tilewarptype[index])
5431 {
5432 case wtCAVE:
5433 case wtNOWARP:
5434 break;
5435
5436 default:
5437 goto_dmapscr(dmap, scr);
5438 break;
5439 }
5440 }
5441 else if(type==1)
5442 {
5443 int32_t dmap=screens[currscr].sidewarpdmap[index];
5444 int32_t scr=screens[currscr].sidewarpscr[index];
5445
5446 switch(screens[currscr].sidewarptype[index])
5447 {
5448 case wtCAVE:
5449 case wtNOWARP:
5450 break;
5451
5452 default:
5453 goto_dmapscr(dmap, scr);
5454 break;
5455 }
5456 }
5457 }
5458
5459 extern int32_t prv_twon;
5460
5461 void zmap::prv_dowarp(int32_t type, int32_t index)
5462 {
5463 if(type==0)
5464 {
5465
5466 int32_t dmap=prvscr.tilewarpdmap[index];
5467 int32_t scr=prvscr.tilewarpscr[index];
5468
5469 switch(prvscr.tilewarptype[index])
5470 {
5471 case wtCAVE:
5472 case wtNOWARP:
5473 break;
5474
5475 default:
5476 //setCurrMap(DMaps[dmap].map);
5477 //setCurrScr(scr+DMaps[dmap].xoff);
5478 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5479 loadlvlpal(getcolor());
5480 rebuild_trans_table();
5481 //prv_cmbcycle=0;
5482 break;
5483 }
5484 }
5485 else if(type==1)
5486 {
5487 int32_t dmap=prvscr.sidewarpdmap[index];
5488 int32_t scr=prvscr.sidewarpscr[index];
5489
5490 switch(prvscr.sidewarptype[index])
5491 {
5492 case wtCAVE:
5493 case wtNOWARP:
5494 break;
5495
5496 default:
5497 //setCurrMap(DMaps[dmap].map);
5498 //setCurrScr(scr+DMaps[dmap].xoff);
5499 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5500 loadlvlpal(getcolor());
5501 rebuild_trans_table();
5502 //prv_cmbcycle=0;
5503 break;
5504 }
5505 }
5506
5507 if(prv_twon)
5508 {
5509 prv_time=get_prvscr()->timedwarptics;
5510 }
5511
5512 //also reset FFC information (so that changers will work correctly) -DD
5513 memset(ffposx,0xFF,sizeof(int16_t)*32);
5514 memset(ffposy,0xFF,sizeof(int16_t)*32);
5515 memset(ffprvx,0xFF,sizeof(float)*32);
5516 memset(ffprvy,0xFF,sizeof(float)*32);
5517 }
5518
5519 void zmap::dowarp2(int32_t ring,int32_t index)
5520 {
5521 set_warpback();
5522 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5523 }
5524
5525 void zmap::set_warpback()
5526 {
5527 warpbackmap = currmap;
5528 warpbackscreen = currscr;
5529 }
5530 bool zmap::has_warpback()
5531 {
5532 return warpbackmap && warpbackscreen
5533 && !(warpbackmap == currmap && warpbackscreen == currscr);
5534 }
5535 void zmap::warpback()
5536 {
5537 if(!has_warpback())
5538 return;
5539 int m = currmap, s = currscr;
5540 goto_mapscr(*warpbackmap, *warpbackscreen);
5541 warpbackmap = m;
5542 warpbackscreen = s;
5543 }
5544
5545 bool save_msgstrs(const char *path)
5546 {
5547 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5548
5549 if(!f)
5550 {
5551 return false;
5552 }
5553
5554 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5555 {
5556 pack_fclose(f);
5557 return true;
5558 }
5559
5560 pack_fclose(f);
5561 return false;
5562 }
5563
5564 1 bool save_strings_tsv(const char *path)
5565 {
5566 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5567
5568
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5569 {
5570 return false;
5571 }
5572
5573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5574 {
5575 1 pack_fclose(f);
5576 1 return true;
5577 }
5578
5579 pack_fclose(f);
5580 return false;
5581 1 }
5582
5583 bool save_msgstrs_text(const char *path)
5584 {
5585 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5586
5587 if(!f)
5588 {
5589 return false;
5590 }
5591
5592 if(writestrings_text(f)==0)
5593 {
5594 pack_fclose(f);
5595 return true;
5596 }
5597
5598 pack_fclose(f);
5599 return false;
5600 }
5601
5602 bool load_msgstrs(const char *path, int32_t startstring)
5603 {
5604 //these are here to bypass compiler warnings about unused arguments
5605 startstring=startstring;
5606
5607 dword section_id;
5608 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5609
5610 if(!f)
5611 {
5612 return false;
5613 }
5614
5615 if(!p_mgetl(&section_id,f))
5616 {
5617 return false;
5618 }
5619
5620 if(section_id==ID_STRINGS)
5621 {
5622 if(readstrings(f, &header)==0)
5623 {
5624 pack_fclose(f);
5625 return true;
5626 }
5627 else
5628 {
5629 pack_fclose(f);
5630 return false;
5631 }
5632 }
5633
5634 pack_fclose(f);
5635 return false;
5636 }
5637
5638 bool load_strings_tsv(const char *path)
5639 {
5640 try
5641 {
5642 parse_strings_tsv(util::read_text_file(path));
5643 }
5644 catch (std::exception& ex)
5645 {
5646 InfoDialog("Import .tsv Error", ex.what()).show();
5647 return false;
5648 }
5649 return true;
5650 }
5651
5652 bool save_pals(const char *path)
5653 {
5654 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5655
5656 if(!f)
5657 {
5658 return false;
5659 }
5660
5661 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5662 {
5663 pack_fclose(f);
5664 return true;
5665 }
5666
5667 pack_fclose(f);
5668 return false;
5669 }
5670
5671 bool load_pals(const char *path, int32_t startcset)
5672 {
5673 dword section_id;
5674 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5675
5676 if(!f)
5677 {
5678 return false;
5679 }
5680
5681 if(!p_mgetl(&section_id,f))
5682 {
5683 return false;
5684 }
5685
5686 if(section_id==ID_CSETS)
5687 {
5688 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5689 {
5690 pack_fclose(f);
5691 loadlvlpal(Color);
5692 return true;
5693 }
5694 else
5695 {
5696 pack_fclose(f);
5697 return false;
5698 }
5699 }
5700
5701 return false;
5702 }
5703
5704 bool save_dmaps(const char *path)
5705 {
5706 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5707
5708 if(!f)
5709 {
5710 return false;
5711 }
5712
5713 if(writedmaps(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXDMAPS)==0)
5714 {
5715 pack_fclose(f);
5716 return true;
5717 }
5718
5719 pack_fclose(f);
5720 return false;
5721 }
5722
5723 bool load_dmaps(const char *path, int32_t startdmap)
5724 {
5725 dword section_id;
5726 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5727
5728 if(!f)
5729 {
5730 return false;
5731 }
5732
5733 if(!p_mgetl(&section_id,f))
5734 {
5735 return false;
5736 }
5737
5738 if(section_id==ID_DMAPS)
5739 {
5740 if(readdmaps(f, NULL, 0x250, 33, startdmap, MAXDMAPS-startdmap)==0)
5741 {
5742 pack_fclose(f);
5743 return true;
5744 }
5745 else
5746 {
5747 pack_fclose(f);
5748 return false;
5749 }
5750 }
5751
5752 return false;
5753 }
5754 bool save_combos(const char *path)
5755 {
5756 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5757
5758 if(!f)
5759 {
5760 return false;
5761 }
5762
5763 reset_combo_animations();
5764 reset_combo_animations2();
5765
5766 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)==0)
5767 {
5768 pack_fclose(f);
5769 return true;
5770 }
5771
5772 pack_fclose(f);
5773 return false;
5774 }
5775
5776 bool load_combos(const char *path, int32_t startcombo)
5777 {
5778 dword section_id;
5779 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5780
5781 if(!f)
5782 {
5783 return false;
5784 }
5785
5786 if(!p_mgetl(&section_id,f))
5787 {
5788 return false;
5789 }
5790
5791 if(section_id==ID_COMBOS)
5792 {
5793 if(readcombos(f, NULL, 0x250, 33, startcombo, MAXCOMBOS-startcombo)==0)
5794 {
5795 pack_fclose(f);
5796 return true;
5797 }
5798 else
5799 {
5800 pack_fclose(f);
5801 return false;
5802 }
5803 }
5804
5805 return false;
5806 }
5807
5808 bool save_tiles(const char *path)
5809 {
5810 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5811
5812 if(!f)
5813 {
5814 return false;
5815 }
5816
5817 // reset_combo_animations();
5818 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)==0)
5819 {
5820 pack_fclose(f);
5821 return true;
5822 }
5823
5824 pack_fclose(f);
5825 return false;
5826 }
5827
5828 bool load_tiles(const char *path, int32_t starttile)
5829 {
5830 dword section_id;
5831 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5832
5833 if(!f)
5834 {
5835 return false;
5836 }
5837
5838 if(!p_mgetl(&section_id,f))
5839 {
5840 return false;
5841 }
5842
5843 if(section_id==ID_TILES)
5844 {
5845 if(readtiles(f, newtilebuf, NULL, 0x250, 33, starttile, NEWMAXTILES-starttile, false)==0)
5846 {
5847 pack_fclose(f);
5848 return true;
5849 }
5850 else
5851 {
5852 pack_fclose(f);
5853 init_tiles(true, &header);
5854 return false;
5855 }
5856 }
5857
5858 return false;
5859 }
5860
5861 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5862 bool save_guys(const char *path)
5863 {
5864 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5865
5866 if(!f)
5867 {
5868 return false;
5869 }
5870
5871 /*
5872 int32_t id = ID_GUYS;
5873 if(!p_mputl(id,f))
5874 {
5875 return false;
5876 }
5877 */
5878
5879 zquestheader h;
5880 h.zelda_version = 0x250;
5881 h.build = 21;
5882
5883 if(writeguys(f, &h)==0)
5884 {
5885 pack_fclose(f);
5886 return true;
5887 }
5888
5889 pack_fclose(f);
5890 return false;
5891 }
5892
5893 bool load_guys(const char *path)
5894 {
5895 dword section_id;
5896 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5897
5898 if(!f)
5899 {
5900 return false;
5901 }
5902
5903 if(!p_mgetl(&section_id,f))
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 zquestheader h;
5910 h.zelda_version = 0x250;
5911 h.build = 21;
5912
5913 if(section_id==ID_GUYS)
5914 {
5915 if(readguys(f, &h)==0)
5916 {
5917 pack_fclose(f);
5918 return true;
5919 }
5920 }
5921
5922 pack_fclose(f);
5923 return false;
5924 }
5925
5926
5927 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5928 bool save_combo_alias(const char *path)
5929 {
5930 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5931
5932 if(!f)
5933 {
5934 return false;
5935 }
5936
5937 zquestheader h;
5938 h.zelda_version = 0x250;
5939 h.build = 21;
5940
5941 if(writecomboaliases(f, 0, 0)==0)
5942 {
5943 pack_fclose(f);
5944 return true;
5945 }
5946
5947 pack_fclose(f);
5948 return false;
5949 }
5950
5951 bool load_combo_alias(const char *path)
5952 {
5953 dword section_id;
5954 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5955
5956 if(!f)
5957 {
5958 return false;
5959 }
5960
5961 if(!p_mgetl(&section_id,f))
5962 {
5963 pack_fclose(f);
5964 return false;
5965 }
5966
5967 zquestheader h;
5968 h.zelda_version = 0x250;
5969 h.build = 21;
5970
5971 if(section_id==ID_COMBOALIASES)
5972 {
5973 if(readcomboaliases(f, &h, 0, 0)==0)
5974 {
5975 pack_fclose(f);
5976 return true;
5977 }
5978 }
5979
5980 pack_fclose(f);
5981 return false;
5982 }
5983
5984 bool load_zgp(const char *path)
5985 {
5986 dword section_id;
5987 dword section_version;
5988 dword section_cversion;
5989 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5990
5991 if(!f)
5992 return false;
5993
5994 if(!p_mgetl(&section_id,f))
5995 {
5996 pack_fclose(f);
5997 return false;
5998 }
5999
6000 if(section_id!=ID_GRAPHICSPACK)
6001 {
6002 pack_fclose(f);
6003 return false;
6004 }
6005
6006 //section version info
6007 if(!p_igetw(&section_version,f))
6008 {
6009 return 2;
6010 }
6011
6012 if(!p_igetw(&section_cversion,f))
6013 {
6014 return 3;
6015 }
6016
6017 //tiles
6018 if(!p_mgetl(&section_id,f))
6019 {
6020 pack_fclose(f);
6021 return false;
6022 }
6023
6024 if(section_id==ID_TILES)
6025 {
6026 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
6027 {
6028 pack_fclose(f);
6029 init_tiles(true, &header);
6030 return false;
6031 }
6032 }
6033 else
6034 {
6035 pack_fclose(f);
6036 return false;
6037 }
6038
6039 //combos
6040 if(!p_mgetl(&section_id,f))
6041 {
6042 pack_fclose(f);
6043 return false;
6044 }
6045
6046 if(section_id==ID_COMBOS)
6047 {
6048 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6049 {
6050 pack_fclose(f);
6051 return false;
6052 }
6053 }
6054 else
6055 {
6056 pack_fclose(f);
6057 return false;
6058 }
6059
6060 //palettes
6061 if(!p_mgetl(&section_id,f))
6062 {
6063 pack_fclose(f);
6064 return false;
6065 }
6066
6067 if(section_id==ID_CSETS)
6068 {
6069 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6070 {
6071 pack_fclose(f);
6072 return false;
6073 }
6074 }
6075 else
6076 {
6077 pack_fclose(f);
6078 return false;
6079 }
6080
6081 //items
6082 if(!p_mgetl(&section_id,f))
6083 {
6084 pack_fclose(f);
6085 return false;
6086 }
6087
6088 if(section_id==ID_ITEMS)
6089 {
6090 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6091 {
6092 pack_fclose(f);
6093 return false;
6094 }
6095 }
6096 else
6097 {
6098 pack_fclose(f);
6099 return false;
6100 }
6101
6102 //weapons
6103 if(!p_mgetl(&section_id,f))
6104 {
6105 pack_fclose(f);
6106 return false;
6107 }
6108
6109 if(section_id==ID_WEAPONS)
6110 {
6111 if(readweapons(f, &header)!=0)
6112 {
6113 pack_fclose(f);
6114 return false;
6115 }
6116 }
6117 else
6118 {
6119 pack_fclose(f);
6120 return false;
6121 }
6122
6123 //read the triforce pieces info and make sure it worked
6124 //really do this?
6125
6126 //read the game icons info and make sure it worked
6127 if(!p_mgetl(&section_id,f))
6128 {
6129 pack_fclose(f);
6130 return false;
6131 }
6132
6133 if(section_id==ID_ICONS)
6134 {
6135 if(readgameicons(f, &header, &QMisc)!=0)
6136 {
6137 pack_fclose(f);
6138 return false;
6139 }
6140 }
6141 else
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 //read the misc colors info and map styles info and make sure it worked
6148 if(!p_mgetl(&section_id,f))
6149 {
6150 pack_fclose(f);
6151 return false;
6152 }
6153
6154 if(section_id==ID_COLORS)
6155 {
6156 if(readmisccolors(f, &header, &QMisc)!=0)
6157 {
6158 pack_fclose(f);
6159 return false;
6160 }
6161 }
6162 else
6163 {
6164 pack_fclose(f);
6165 return false;
6166 }
6167
6168 //read the door combo sets and make sure it worked
6169 if(!p_mgetl(&section_id,f))
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 if(section_id==ID_DOORS)
6176 {
6177 if(readdoorcombosets(f, &header)!=0)
6178 {
6179 pack_fclose(f);
6180 return false;
6181 }
6182 }
6183 else
6184 {
6185 pack_fclose(f);
6186 return false;
6187 }
6188
6189 //read the template screens and make sure it worked
6190 //really do this?
6191
6192 //yay! it worked! close the file and say everything was ok.
6193 loadlvlpal(Color);
6194 setup_combo_animations();
6195 setup_combo_animations2();
6196 pack_fclose(f);
6197 return true;
6198 }
6199
6200 bool save_zgp(const char *path)
6201 {
6202 reset_combo_animations();
6203 reset_combo_animations2();
6204
6205 //open the file
6206 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6207
6208 if(!f)
6209 return false;
6210
6211 dword section_id=ID_GRAPHICSPACK;
6212 dword section_version=V_GRAPHICSPACK;
6213 dword section_cversion=CV_GRAPHICSPACK;
6214
6215 //section id
6216 if(!p_mputl(section_id,f))
6217 {
6218 return 1;
6219 }
6220
6221 //section version info
6222 if(!p_iputw(section_version,f))
6223 {
6224 return 2;
6225 }
6226
6227 if(!p_iputw(section_cversion,f))
6228 {
6229 return 3;
6230 }
6231
6232 //tiles
6233 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6234 {
6235 pack_fclose(f);
6236 return false;
6237 }
6238
6239 //combos
6240 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6241 {
6242 pack_fclose(f);
6243 return false;
6244 }
6245
6246 //palettes
6247 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6248 {
6249 pack_fclose(f);
6250 return false;
6251 }
6252
6253 //items
6254 if(writeitems(f, &header)!=0)
6255 {
6256 pack_fclose(f);
6257 return false;
6258 }
6259
6260 //weapons
6261 if(writeweapons(f, &header)!=0)
6262 {
6263 pack_fclose(f);
6264 return false;
6265 }
6266
6267 //write the triforce pieces info and make sure it worked
6268 //really do this?
6269
6270 //write the game icons info and make sure it worked
6271 if(writegameicons(f, &header)!=0)
6272 {
6273 pack_fclose(f);
6274 return false;
6275 }
6276
6277 //write the misc colors info and map styles info and make sure it worked
6278 if(writemisccolors(f, &header)!=0)
6279 {
6280 pack_fclose(f);
6281 return false;
6282 }
6283
6284 //write the door combo sets and make sure it worked
6285 if(writedoorcombosets(f, &header)!=0)
6286 {
6287 pack_fclose(f);
6288 return false;
6289 }
6290
6291 //write the template screens and make sure it worked
6292 //really do this?
6293
6294 pack_fclose(f);
6295 return true;
6296 }
6297
6298 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6299 {
6300 //open the file
6301 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6302
6303 if(!f)
6304 return false;
6305
6306 dword section_id=ID_SUBSCREEN;
6307 dword s_version=V_SUBSCREEN;
6308 dword s_cversion=CV_SUBSCREEN;
6309
6310 if(!p_mputl(section_id,f))
6311 {
6312 pack_fclose(f);
6313 return false;
6314 }
6315
6316 if(!p_iputw(s_version,f))
6317 {
6318 pack_fclose(f);
6319 return false;
6320 }
6321
6322 if(!p_iputw(s_cversion,f))
6323 {
6324 pack_fclose(f);
6325 return false;
6326 }
6327
6328 if(savefrom.write(f))
6329 {
6330 pack_fclose(f);
6331 return false;
6332 }
6333
6334 pack_fclose(f);
6335 return true;
6336 }
6337
6338 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6339 {
6340 //open the file
6341 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6342
6343 if(!f)
6344 return false;
6345
6346 dword section_id;
6347 dword s_version;
6348 dword s_cversion;
6349
6350 if(!p_mgetl(&section_id,f))
6351 {
6352 pack_fclose(f);
6353 return false;
6354 }
6355
6356 if(section_id!=ID_SUBSCREEN)
6357 {
6358 pack_fclose(f);
6359 return false;
6360 }
6361
6362 if(!p_igetw(&s_version,f))
6363 {
6364 pack_fclose(f);
6365 return false;
6366 }
6367
6368 if(!p_igetw(&s_cversion,f))
6369 {
6370 pack_fclose(f);
6371 return false;
6372 }
6373
6374 if(s_version < 8)
6375 {
6376 subscreen_group g;
6377 memset(&g,0,sizeof(subscreen_group));
6378 if(read_one_old_subscreen(f,&g,s_version)!=0)
6379 {
6380 pack_fclose(f);
6381 return false;
6382 }
6383 if(g.ss_type != loadto.sub_type)
6384 {
6385 pack_fclose(f);
6386 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6387 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6388 return false;
6389 }
6390 loadto.clear();
6391 if(g.objects[0].type != ssoNULL)
6392 loadto.load_old(g);
6393 }
6394 else
6395 {
6396 ZCSubscreen tmp = ZCSubscreen();
6397 if (tmp.read(f, s_version))
6398 {
6399 pack_fclose(f);
6400 return false;
6401 }
6402 if(tmp.sub_type != loadto.sub_type)
6403 {
6404 pack_fclose(f);
6405 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6406 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6407 return false;
6408 }
6409 loadto.clear();
6410 loadto = tmp;
6411 }
6412
6413 pack_fclose(f);
6414 return true;
6415 }
6416
6417 bool setMapCount2(int32_t c)
6418 {
6419 int32_t oldmapcount=map_count;
6420 int32_t currmap=Map.getCurrMap();
6421
6422 bound(c,1,MAXMAPS);
6423 map_count=c;
6424
6425 try
6426 {
6427 TheMaps.resize(c*MAPSCRS);
6428 Map.force_refr_pointer();
6429 map_autolayers.resize(c*6);
6430 }
6431 catch(...)
6432 {
6433 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6434 return false;
6435 }
6436
6437 bound(currmap,0,c-1);
6438 if(map_count>oldmapcount)
6439 {
6440 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6441 {
6442 Map.setCurrMap(mc);
6443
6444 for(int32_t ms=0; ms<MAPSCRS; ms++)
6445 {
6446 Map.clearscr(ms);
6447 }
6448 }
6449 Map.setCurrMap(currmap);
6450 }
6451 else
6452 {
6453 Map.setCurrMap(currmap);
6454 if(!layers_valid(Map.CurrScr()))
6455 fix_layers(Map.CurrScr(), false);
6456
6457 for(int32_t i=0; i<MAXDMAPS; i++)
6458 {
6459 if(DMaps[i].map>=map_count)
6460 {
6461 DMaps[i].map=map_count-1;
6462 }
6463 }
6464 }
6465
6466 return true;
6467 }
6468
6469 extern BITMAP *bmap;
6470
6471 static bool loading_file_new = false;
6472 1 int32_t init_quest()
6473 {
6474 char qstdat_string[2048];
6475 1 strcpy(qstdat_string, "modules/classic/default.qst");
6476
6477 char buf[2048];
6478
6479 1 loading_file_new = true;
6480 1 load_quest(qstdat_string);
6481 1 loading_file_new = false;
6482
6483 1 sprintf(buf,"ZC Editor - Untitled Quest");
6484 1 set_window_title(buf);
6485 1 zinit.last_map = 0;
6486 1 zinit.last_screen = 0;
6487
6488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6489 {
6490 destroy_bitmap(bmap);
6491 bmap=NULL;
6492 }
6493
6494 1 return 0;
6495 }
6496
6497 void set_questpwd(std::string_view pwd, bool use_keyfile)
6498 {
6499 header.use_keyfile=use_keyfile;
6500
6501 // string_view actually has some quirks that make it less than ideal here.
6502 // It'd probably be best to replace it, but this works for now.
6503 memset(header.password, 0, 256);
6504 strcpy(header.password, pwd.data());
6505 header.dirty_password=true;
6506
6507 cvs_MD5Context ctx;
6508 cvs_MD5Init(&ctx);
6509 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6510 cvs_MD5Final(header.pwd_hash, &ctx);
6511 }
6512
6513
6514 bool is_null_pwd_hash(uint8_t *pwd_hash)
6515 {
6516 cvs_MD5Context ctx;
6517 uint8_t md5sum[16];
6518 char pwd[2]="";
6519
6520 cvs_MD5Init(&ctx);
6521 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6522 cvs_MD5Final(md5sum, &ctx);
6523
6524 return (memcmp(md5sum,pwd_hash,16)==0);
6525 }
6526
6527 static DIALOG pwd_dlg[] =
6528 {
6529 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6530 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6531 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6532 // 2 (filename)
6533 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6534 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6535 // 4 (challenge hash)
6536 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6537 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6538 // 6 (password)
6539 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6540 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6541 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6542 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6543 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6544 };
6545
6546 int32_t reverse_string(char* str)
6547 {
6548
6549 if(NULL==str)
6550 {
6551 return -1; //no string
6552 }
6553
6554 int32_t l=(int32_t)strlen(str)-1; //get the string length
6555
6556 if(1==l)
6557 {
6558 return 1;
6559 }
6560
6561 char c;
6562
6563 for(int32_t x=0; x < l; x++,l--)
6564 {
6565 c = str[x];
6566 str[x] = str[l];
6567 str[l] = c;
6568 }
6569
6570 return 0;
6571 }
6572
6573 #ifdef __GNUC__
6574 #pragma GCC diagnostic push
6575 #pragma GCC diagnostic ignored "-Wunreachable-code"
6576 #endif
6577
6578 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6579 {
6580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (is_headless())
6581 9 return 1;
6582
6583 #ifdef __EMSCRIPTEN__
6584 return 1;
6585 #endif
6586
6587 //Protection against compiling a release version with password protection off.
6588 static bool passguard = false;
6589
6590 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6591 #define MUST_HAVE_PASSWORD
6592 passguard = true;
6593 #endif
6594
6595 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6596 #if (defined _MSC_VER || defined _NPASS)
6597 return 1;
6598 #endif
6599 #endif
6600 if(devpwd()) return 1;
6601
6602 char hash_string[33];
6603
6604 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6605 {
6606 return 1;
6607 }
6608
6609 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6610 return true;
6611
6612 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6613 pwd_dlg[2].dp=get_filename(filename);
6614 cvs_MD5Context ctx;
6615 uint8_t md5sum[16]={0};
6616 char response[33]="";
6617 char prompt[256]="";
6618
6619 memcpy(md5sum, hdr->pwd_hash, 16);
6620
6621 for(int32_t i=0; i<300; ++i)
6622 {
6623 for(int32_t j=0; j<16; ++j)
6624 {
6625 sprintf(response+j*2, "%02x", md5sum[j]);
6626 }
6627
6628 if(i&1)
6629 {
6630 reverse_string(response);
6631 }
6632
6633 if(i==149)
6634 {
6635 strcpy(hash_string, response);
6636 }
6637
6638 cvs_MD5Init(&ctx);
6639 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6640 cvs_MD5Final(md5sum, &ctx);
6641 }
6642
6643 pwd_dlg[4].dp=hash_string;
6644
6645 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6646 {
6647 sprintf(prompt,"%s",response);
6648 }
6649
6650 pwd_dlg[6].dp=prompt;
6651
6652 large_dialog(pwd_dlg);
6653
6654 int32_t cancel = do_zqdialog(pwd_dlg,6);
6655
6656 if(cancel == 8)
6657 return 2;
6658
6659 bool ret=check_questpwd(hdr, prompt);
6660
6661 if(!ret)
6662 {
6663 ret=(strcmp(response,prompt)==0);
6664 }
6665 return ret ? 1 : 0;
6666 9 }
6667
6668 void set_rules(byte* newrules);
6669 8 void popup_bugfix_dlg(const char* cfg)
6670 {
6671 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6672
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6673 {
6674
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6675
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6676 "\nWould you like to apply them?"
6677 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6678 8 [&](bool ret,bool dsa)
6679 {
6680 if(ret)
6681 {
6682 applyRuleTemplate(ruletemplateFixCompat);
6683 }
6684 if(dsa)
6685 {
6686 zc_set_config("zquest",cfg,1);
6687 }
6688 },
6689
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6690 0,false, //timeout - none
6691 true //"Don't show this again"
6692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6693 8 }
6694 8 }
6695
6696 #ifdef __GNUC__
6697 #pragma GCC diagnostic pop
6698 #endif
6699
6700 // wrapper to reinitialize everything on an error
6701 9 int32_t load_quest(const char *filename, bool show_progress)
6702 {
6703 char buf[2048];
6704 // if(encrypted)
6705 // setPackfilePassword(datapwd);
6706 byte skip_flags[4];
6707
6708
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6709 {
6710 36 skip_flags[i]=0;
6711 36 }
6712
2/2
✓ Branch 0 taken 6219 times.
✓ Branch 1 taken 9 times.
6228 for(int32_t i=0; i<qr_MAX; i++)
6713 6219 set_qr(i,0);
6714 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6715
6716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6717 {
6718 init_quest();
6719 }
6720 else
6721 {
6722 9 int32_t accessret = quest_access(filename, &header);
6723
6724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6725 {
6726 init_quest();
6727
6728 if(accessret == 0)
6729 ret=qe_pwd;
6730 else
6731 ret=qe_cancel;
6732 }
6733 else
6734 {
6735 9 Map.clear();
6736 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6737 9 Map.setCurrScr(zinit.last_screen);
6738 extern int32_t current_mappage;
6739 9 current_mappage = 0;
6740 9 bool found_default = false;
6741
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6742 {
6743 65 auto &pg = map_page[q];
6744
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6745 {
6746 2 current_mappage = q;
6747 2 break;
6748 }
6749
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6750 56 continue;
6751 else
6752 {
6753 7 current_mappage = q;
6754 7 found_default = true;
6755 }
6756 7 }
6757 9 refresh(rALL);
6758 9 refresh_pal();
6759 9 set_rules(quest_rules);
6760 9 saved = true;
6761
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6762 8 popup_bugfix_dlg("dsa_compatrule");
6763
6764
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(bmap != NULL)
6765 {
6766 destroy_bitmap(bmap);
6767 bmap=NULL;
6768 }
6769
6770
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (show_progress)
6771 {
6772 1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6773 1 set_window_title(buf);
6774 1 }
6775 }
6776 }
6777
6778 9 Map.ClearCommandHistory();
6779
6780 9 return ret;
6781 }
6782
6783 int32_t load_tileset(const char *filename, dword tsetflags)
6784 {
6785 char buf[2048];
6786 byte skip_flags[4];
6787
6788 for(int32_t i=0; i<4; ++i)
6789 skip_flags[i]=0;
6790 for(int32_t i=0; i<qr_MAX; i++)
6791 set_qr(i,0);
6792 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6793
6794 if(ret!=qe_OK)
6795 init_quest();
6796 else
6797 {
6798 int32_t accessret = quest_access(filename, &header);
6799
6800 if(accessret != 1)
6801 {
6802 init_quest();
6803
6804 if(accessret == 0)
6805 ret=qe_pwd;
6806 else
6807 ret=qe_cancel;
6808 }
6809 else
6810 {
6811 Map.clear();
6812 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6813 Map.setCurrScr(zinit.last_screen);
6814 extern int32_t current_mappage;
6815 current_mappage = 0;
6816 bool found_default = false;
6817 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6818 {
6819 auto &pg = map_page[q];
6820 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6821 {
6822 current_mappage = q;
6823 break;
6824 }
6825 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6826 continue;
6827 else
6828 {
6829 current_mappage = q;
6830 found_default = true;
6831 }
6832 }
6833 refresh(rALL);
6834 refresh_pal();
6835 set_rules(quest_rules);
6836 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6837 popup_bugfix_dlg("dsa_compatrule");
6838
6839 if(bmap != NULL)
6840 {
6841 destroy_bitmap(bmap);
6842 bmap=NULL;
6843 }
6844
6845 set_window_title("ZC Editor - Untitled Quest");
6846 first_save = saved = false;
6847 memset(filepath,0,255);
6848 memset(temppath,0,255);
6849 }
6850 }
6851
6852 Map.ClearCommandHistory();
6853
6854 return ret;
6855 }
6856
6857 60 bool write_midi(MIDI *m,PACKFILE *f)
6858 {
6859 int32_t c;
6860
6861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6862
6863
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6864 {
6865
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6866
6867
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6868 {
6869
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6870 return false;
6871 492 }
6872 1920 }
6873
6874 60 return true;
6875 60 }
6876
6877 bool write_music(int32_t format, MIDI* m, PACKFILE *f)
6878 {
6879 // format - data format (midi, nsf, ...)
6880 // m - pointer to data.
6881
6882 int32_t c;
6883
6884 switch(format)
6885 {
6886 case MFORMAT_MIDI:
6887
6888 if(!p_mputw(m->divisions,f)) return false;
6889
6890 for(c=0; c<MIDI_TRACKS; c++)
6891 {
6892 if(!p_mputl(m->track[c].len,f)) return false;
6893
6894 if(m->track[c].len > 0)
6895 {
6896 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6897 return false;
6898 }
6899 }
6900
6901 break;
6902
6903 case MFORMAT_NSF:
6904
6905 break;
6906
6907 default:
6908 return false;
6909 break;
6910 }
6911
6912 return true;
6913 }
6914
6915 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6916 {
6917 6 dword section_id=ID_HEADER;
6918 6 dword section_version=V_HEADER;
6919 6 dword section_cversion=CV_HEADER;
6920 6 dword section_size=0;
6921
6922 //file header string
6923
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6924 {
6925 new_return(1);
6926 }
6927
6928 //section id
6929
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6930 {
6931 new_return(2);
6932 }
6933
6934 //section version info
6935
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6936 {
6937 new_return(3);
6938 }
6939
6940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6941 {
6942 new_return(4);
6943 }
6944
6945
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6946 {
6947 12 fake_pack_writing=(writecycle==0);
6948
6949 //section size
6950
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6951 {
6952 new_return(5);
6953 }
6954
6955 12 writesize=0;
6956
6957 //finally... section data
6958
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6959 {
6960 new_return(6);
6961 }
6962
6963
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6964 {
6965 new_return(7);
6966 }
6967
6968
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6969 {
6970 new_return(8);
6971 }
6972
6973
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6974 {
6975 new_return(10);
6976 }
6977
6978
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6979 {
6980 new_return(11);
6981 }
6982
6983
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6984 {
6985 new_return(12);
6986 }
6987
6988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6989 {
6990 new_return(13);
6991 }
6992
6993
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6994 {
6995 new_return(14);
6996 }
6997
6998
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
6999 {
7000 new_return(15);
7001 }
7002
7003
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
7004 {
7005 new_return(16);
7006 }
7007
7008
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
7009 {
7010 new_return(17);
7011 }
7012
7013
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
7014 {
7015 new_return(19);
7016 }
7017
7018
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
7019 //this is for map count, it seems. -Z
7020 {
7021 new_return(20);
7022 }
7023
7024 12 auto version = getVersion();
7025
7026
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
7027 {
7028 new_return(21);
7029 }
7030
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
7031 {
7032 new_return(22);
7033 }
7034
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
7035 {
7036 new_return(23);
7037 }
7038 // Fourth component is deprecated.
7039
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7040 {
7041 new_return(24);
7042 }
7043
7044 // Numerous prerelease stages is deprecated.
7045
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7046 {
7047 new_return(25);
7048 }
7049
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7050 {
7051 new_return(26);
7052 }
7053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7054 {
7055 new_return(27);
7056 }
7057
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7058 {
7059 new_return(28);
7060 }
7061
7062
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
7063 {
7064 new_return(29);
7065 }
7066
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
7067 {
7068 new_return(30);
7069 }
7070
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
7071 {
7072 new_return(31);
7073 }
7074
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
7075 {
7076 new_return(32);
7077 }
7078
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
7079 {
7080 new_return(33);
7081 }
7082
7083
7084
7085 char tempsig[256];
7086 12 memset(tempsig, 0, 256);
7087 12 strcpy(tempsig, DEV_SIGNOFF);
7088
7089
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
7090 {
7091 new_return(34);
7092 }
7093
7094 char tempcompilersig[256];
7095 12 memset(tempcompilersig, 0, 256);
7096 12 strcpy(tempcompilersig, COMPILER_NAME);
7097
7098
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
7099 {
7100 new_return(35);
7101 }
7102
7103 char tempcompilerversion[256];
7104 12 memset(tempcompilerversion, 0, 256);
7105 #ifdef _MSC_VER
7106 zc_itoa(_MSC_VER,tempcompilerversion,10);
7107 #else
7108 12 strcpy(tempcompilerversion, COMPILER_VERSION);
7109 #endif
7110
7111
7112
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
7113 {
7114 new_return(36);
7115 }
7116
7117
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
7118 {
7119 new_return(37);
7120 }
7121
7122
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7123 {
7124 new_return(38);
7125 }
7126 #ifdef _MSC_VER
7127 if(!p_iputl((_MSC_VER / 100),f))
7128 {
7129 new_return(39);
7130 }
7131 #else
7132
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7133 {
7134 new_return(39);
7135 }
7136 #endif
7137
7138
7139
7140 #ifdef _MSC_VER
7141 if(!p_iputl((_MSC_VER % 100),f))
7142 {
7143 new_return(41);
7144 }
7145 #else
7146
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7147 {
7148 new_return(41);
7149 }
7150 #endif
7151
7152 #ifdef _MSC_VER
7153 # if _MSC_VER >= 1400
7154 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7155 {
7156 new_return(40);
7157 }
7158 # else
7159 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7160 {
7161 new_return(40);
7162 }
7163 #endif
7164 #else
7165
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7166 {
7167 new_return(40);
7168 }
7169 #endif
7170
7171 #ifdef _MSC_VER
7172 if(!p_iputl((_MSC_BUILD),f))
7173 {
7174 new_return(42);
7175 }
7176 #else
7177
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7178 {
7179 new_return(42);
7180 }
7181 #endif
7182
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7183 {
7184 new_return(43);
7185 }
7186
7187 char tempmodulename[1024];
7188 12 memset(tempmodulename, 0, 1024);
7189 12 strcpy(tempmodulename, moduledata.module_name);
7190
7191
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7192 {
7193 new_return(44);
7194 }
7195
7196 char tempdate[256];
7197 12 memset(tempdate, 0, 256);
7198 12 strcpy(tempdate, __DATE__);
7199
7200
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7201 {
7202 new_return(45);
7203 }
7204 char temptime[256];
7205 12 memset(temptime, 0, 256);
7206 12 strcpy(temptime, __TIME__);
7207
7208
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7209 {
7210 new_return(46);
7211 }
7212
7213
7214 char temptimezone[6];
7215 12 memset(temptimezone, 0, 6);
7216 12 strcpy(temptimezone, __TIMEZONE__);
7217
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7218 {
7219 new_return(47);
7220 }
7221
7222
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7223 {
7224 new_return(48);
7225 }
7226
7227
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7228 {
7229 new_return(49);
7230 }
7231
7232
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7233 {
7234 new_return(50);
7235 }
7236
7237
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7238 {
7239 6 section_size=writesize;
7240 6 }
7241 12 }
7242
7243
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7244 {
7245 char ebuf[80];
7246 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7247 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7248 }
7249
7250 6 new_return(0);
7251 }
7252
7253 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7254 {
7255 //these are here to bypass compiler warnings about unused arguments
7256 6 Header=Header;
7257
7258 6 dword section_id=ID_RULES;
7259 6 dword section_version=V_RULES;
7260 6 dword section_cversion=CV_RULES;
7261 6 dword section_size=0;
7262
7263 //section id
7264
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7265 {
7266 new_return(1);
7267 }
7268
7269 //section version info
7270
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7271 {
7272 new_return(2);
7273 }
7274
7275
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7276 {
7277 new_return(3);
7278 }
7279
7280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7281 {
7282 new_return(6);
7283 }
7284
7285
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7286 {
7287 12 fake_pack_writing=(writecycle==0);
7288
7289 //section size
7290
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7291 {
7292 new_return(4);
7293 }
7294
7295 12 writesize=0;
7296
7297 //finally... section data
7298
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7299 {
7300 new_return(5);
7301 }
7302
7303
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7304 {
7305 6 section_size=writesize;
7306 6 }
7307 12 }
7308
7309
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7310 {
7311 char ebuf[80];
7312 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7313 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7314 }
7315
7316 6 new_return(0);
7317 }
7318
7319
7320 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7321 {
7322 //these are here to bypass compiler warnings about unused arguments
7323 6 Header=Header;
7324
7325 6 dword section_id=ID_DOORS;
7326 6 dword section_version=V_DOORS;
7327 6 dword section_cversion=CV_DOORS;
7328 6 dword section_size=0;
7329
7330 //section id
7331
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7332 {
7333 new_return(1);
7334 }
7335
7336 //section version info
7337
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7338 {
7339 new_return(2);
7340 }
7341
7342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7343 {
7344 new_return(3);
7345 }
7346
7347
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7348 {
7349 12 fake_pack_writing=(writecycle==0);
7350
7351 //section size
7352
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7353 {
7354 new_return(4);
7355 }
7356
7357 12 writesize=0;
7358
7359 //finally... section data
7360
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7361 {
7362 new_return(5);
7363 }
7364
7365
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7366 {
7367 //name
7368
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7369 {
7370 new_return(6);
7371 }
7372
7373 //up door
7374
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7375 {
7376
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7377 {
7378
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7379 {
7380 new_return(7);
7381 }
7382 5904 }
7383 1476 }
7384
7385
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7386 {
7387
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7388 {
7389
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7390 {
7391 new_return(8);
7392 }
7393 5904 }
7394 1476 }
7395
7396 //down door
7397
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7398 {
7399
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7400 {
7401
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7402 {
7403 new_return(9);
7404 }
7405 5904 }
7406 1476 }
7407
7408
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7409 {
7410
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7411 {
7412
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7413 {
7414 new_return(10);
7415 }
7416 5904 }
7417 1476 }
7418
7419
7420 //left door
7421
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7422 {
7423
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7424 {
7425
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7426
7427 {
7428 new_return(11);
7429 }
7430 8856 }
7431 1476 }
7432
7433
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7434 {
7435
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7436 {
7437
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7438 {
7439 new_return(12);
7440 }
7441 8856 }
7442 1476 }
7443
7444 //right door
7445
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7446 {
7447
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7448 {
7449
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7450 {
7451 new_return(13);
7452 }
7453 8856 }
7454 1476 }
7455
7456
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7457 {
7458
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7459 {
7460
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7461 {
7462 new_return(14);
7463 }
7464 8856 }
7465 1476 }
7466
7467
7468 //up bomb rubble
7469
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7470 {
7471
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7472 {
7473 new_return(15);
7474 }
7475 328 }
7476
7477
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7478 {
7479
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7480 {
7481 new_return(16);
7482 }
7483 328 }
7484
7485 //down bomb rubble
7486
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7487 {
7488
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7489 {
7490 new_return(17);
7491 }
7492 328 }
7493
7494
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7495 {
7496
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7497 {
7498 new_return(18);
7499 }
7500 328 }
7501
7502 //left bomb rubble
7503
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7504 {
7505
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7506 {
7507 new_return(19);
7508 }
7509 492 }
7510
7511
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7512 {
7513
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7514 {
7515 new_return(20);
7516 }
7517 492 }
7518
7519 //right bomb rubble
7520
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7521 {
7522
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7523 {
7524 new_return(21);
7525 }
7526 492 }
7527
7528
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7529 {
7530
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7531 {
7532 new_return(22);
7533 }
7534 492 }
7535
7536 //walkthrough stuff
7537
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7538 {
7539
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7540 {
7541 new_return(23);
7542 }
7543 656 }
7544
7545
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7546 {
7547
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7548 {
7549 new_return(24);
7550 }
7551 656 }
7552
7553 //flags
7554
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7555 {
7556
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7557 {
7558 new_return(25);
7559 }
7560 328 }
7561 164 }
7562
7563
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7564 {
7565 6 section_size=writesize;
7566 6 }
7567 12 }
7568
7569
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7570 {
7571 char ebuf[80];
7572 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7573 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7574 }
7575
7576 6 new_return(0);
7577 }
7578
7579 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7580 {
7581 //these are here to bypass compiler warnings about unused arguments
7582 6 version=version;
7583 6 build=build;
7584
7585 6 word dmap_count=count_dmaps();
7586 6 dword section_id=ID_DMAPS;
7587 6 dword section_version=V_DMAPS;
7588 6 dword section_cversion=CV_DMAPS;
7589 6 dword section_size=0;
7590
7591 //section id
7592
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7593 {
7594 new_return(1);
7595 }
7596
7597 //section version info
7598
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7599 {
7600 new_return(2);
7601 }
7602
7603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7604 {
7605 new_return(3);
7606 }
7607
7608
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7609 {
7610 12 fake_pack_writing=(writecycle==0);
7611
7612 //section size
7613
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7614 {
7615 new_return(4);
7616 }
7617
7618 12 writesize=0;
7619
7620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7622
7623 //finally... section data
7624
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7625 {
7626 new_return(5);
7627 }
7628
7629
7630
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7631 {
7632 6144 DMaps[i].validate_subscreens();
7633
7634
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7635 {
7636 new_return(6);
7637 }
7638
7639
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7640 {
7641 new_return(7);
7642 }
7643
7644
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7645 {
7646 new_return(8);
7647 }
7648
7649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7650 {
7651 new_return(9);
7652 }
7653
7654
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7655 {
7656 new_return(10);
7657 }
7658
7659
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7660 {
7661 new_return(11);
7662 }
7663
7664
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7665 {
7666 new_return(12);
7667 }
7668
7669
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7670 {
7671 new_return(13);
7672 }
7673
7674
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7675 {
7676
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7677 {
7678 new_return(14);
7679 }
7680 49152 }
7681
7682
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7683 {
7684 new_return(15);
7685 }
7686
7687
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7688 {
7689 new_return(16);
7690 }
7691
7692
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7693 {
7694 new_return(17);
7695 }
7696
7697
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7698 {
7699 new_return(18);
7700 }
7701
7702
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7703 {
7704 new_return(19);
7705 }
7706
7707
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7708 {
7709 new_return(20);
7710 }
7711
7712
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7713 {
7714 new_return(21);
7715 }
7716
7717
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7718 {
7719 new_return(22);
7720 }
7721
7722
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7723 {
7724 new_return(23);
7725 }
7726
7727
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7728 {
7729 new_return(24);
7730 }
7731
7732
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7733 {
7734 new_return(25);
7735 }
7736
7737
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7738 {
7739 new_return(26);
7740 }
7741
7742
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7743 {
7744 new_return(25);
7745 }
7746
7747
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7748 {
7749 new_return(26);
7750 }
7751
7752
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7753 {
7754 new_return(27);
7755 }
7756
7757 byte disabled[32];
7758 6144 memset(disabled,0,32);
7759
7760
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7761 {
7762
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7763 {
7764 disabled[j/8] |= (1 << (j%8));
7765 }
7766 1572864 }
7767
7768
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7769 {
7770 new_return(28);
7771 }
7772
7773
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7774 {
7775 new_return(29);
7776 }
7777
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7778 {
7779 new_return(30);
7780 }
7781
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7782 {
7783 new_return(31);
7784 }
7785
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7786 {
7787
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7788 {
7789 new_return(32);
7790 }
7791
7792 49152 }
7793
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7794 {
7795
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7796 {
7797
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7798 {
7799 new_return(33);
7800 }
7801 3194880 }
7802 49152 }
7803
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7804 {
7805 new_return(34);
7806 }
7807
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7808 {
7809 new_return(35);
7810 }
7811
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7812 {
7813
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7814 {
7815 new_return(36);
7816 }
7817 49152 }
7818
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7819 {
7820
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7821 {
7822
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7823 {
7824 new_return(37);
7825 }
7826 3194880 }
7827 49152 }
7828
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7829 {
7830 new_return(38);
7831 }
7832
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7833 {
7834
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7835 {
7836 new_return(39);
7837 }
7838 49152 }
7839
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7840 {
7841
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7842 {
7843
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7844 {
7845 new_return(40);
7846 }
7847 3194880 }
7848 49152 }
7849
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7850 {
7851 new_return(41);
7852 }
7853
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7854 {
7855 new_return(42);
7856 }
7857
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7858 {
7859 new_return(43);
7860 }
7861
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7862 {
7863 new_return(44);
7864 }
7865
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7866 {
7867 new_return(45);
7868 }
7869
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7870 new_return(46);
7871
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7872 new_return(47);
7873
7874 // Reserved for z3.
7875
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7876 {
7877
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7878 {
7879
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7880 {
7881 new_return(48);
7882 }
7883 393216 }
7884 49152 }
7885 6144 }
7886
7887
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7888 {
7889 6 section_size=writesize;
7890 6 }
7891 12 }
7892
7893
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7894 {
7895 char ebuf[80];
7896 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7897 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7898 }
7899
7900 6 new_return(0);
7901 }
7902
7903 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7904 {
7905 //these are here to bypass compiler warnings about unused arguments
7906 6 Header=Header;
7907
7908 6 dword section_id=ID_COLORS;
7909 6 dword section_version=V_COLORS;
7910 6 dword section_cversion=CV_COLORS;
7911 6 dword section_size = 0;
7912
7913 //section id
7914
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7915 {
7916 new_return(1);
7917 }
7918
7919
7920 //section version info
7921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7922 {
7923 new_return(2);
7924 }
7925
7926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7927 {
7928 new_return(3);
7929 }
7930
7931
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7932 {
7933 12 fake_pack_writing=(writecycle==0);
7934
7935 //section size
7936
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7937 {
7938 new_return(4);
7939 }
7940
7941 12 writesize=0;
7942
7943
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7944 {
7945 new_return(5);
7946 }
7947
7948
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7949 {
7950 new_return(6);
7951 }
7952
7953
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7954 {
7955 new_return(7);
7956 }
7957
7958
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7959 {
7960 new_return(8);
7961 }
7962
7963
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7964 {
7965 new_return(9);
7966 }
7967
7968
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7969 {
7970 new_return(10);
7971 }
7972
7973
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7974 {
7975 new_return(11);
7976 }
7977
7978
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7979 {
7980 new_return(12);
7981 }
7982
7983
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7984 {
7985 new_return(13);
7986 }
7987
7988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7989 {
7990 new_return(14);
7991 }
7992
7993
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7994 {
7995 new_return(15);
7996 }
7997
7998
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
7999 {
8000 new_return(16);
8001 }
8002
8003
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
8004 {
8005 new_return(17);
8006 }
8007
8008
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
8009 {
8010 new_return(18);
8011 }
8012
8013
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
8014 {
8015 new_return(19);
8016 }
8017
8018
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
8019 {
8020 new_return(20);
8021 }
8022
8023
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
8024 {
8025 new_return(21);
8026 }
8027
8028
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
8029 {
8030 new_return(22);
8031 }
8032
8033
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
8034 {
8035 new_return(23);
8036 }
8037
8038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
8039 {
8040 new_return(24);
8041 }
8042
8043
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
8044 {
8045 new_return(31);
8046 }
8047
8048
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
8049 {
8050 new_return(32);
8051 }
8052
8053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
8054 {
8055 new_return(33);
8056 }
8057
8058
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
8059 {
8060 new_return(34);
8061 }
8062
8063
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
8064 {
8065 new_return(35);
8066 }
8067
8068
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
8069 {
8070 new_return(36);
8071 }
8072
8073
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
8074 {
8075 new_return(37);
8076 }
8077
8078
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8079 {
8080 new_return(38);
8081 }
8082
8083
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8084 {
8085 new_return(39);
8086 }
8087
8088
8089
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8090 {
8091 6 section_size=writesize;
8092 6 }
8093 12 }
8094
8095
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8096 {
8097 char ebuf[80];
8098 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8099 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8100 }
8101
8102 6 new_return(0);
8103 }
8104
8105 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8106 {
8107 //these are here to bypass compiler warnings about unused arguments
8108 6 Header=Header;
8109
8110 6 dword section_id=ID_ICONS;
8111 6 dword section_version=V_ICONS;
8112 6 dword section_cversion=CV_ICONS;
8113 6 dword section_size = 0;
8114
8115 //section id
8116
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8117 {
8118 new_return(1);
8119 }
8120
8121 //section version info
8122
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8123 {
8124 new_return(2);
8125 }
8126
8127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8128 {
8129 new_return(3);
8130 }
8131
8132
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8133 {
8134 12 fake_pack_writing=(writecycle==0);
8135
8136 //section size
8137
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8138 {
8139 new_return(4);
8140 }
8141
8142 12 writesize=0;
8143
8144
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8145 {
8146
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8147 {
8148 new_return(5);
8149 }
8150 48 }
8151
8152
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8153 {
8154 6 section_size=writesize;
8155 6 }
8156 12 }
8157
8158
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8159 {
8160 char ebuf[80];
8161 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8162 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8163 }
8164
8165 6 new_return(0);
8166 }
8167
8168 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8169 {
8170 //these are here to bypass compiler warnings about unused arguments
8171 6 Header=Header;
8172
8173 6 dword section_id=ID_MISC;
8174 6 dword section_version=V_MISC;
8175 6 dword section_cversion=CV_MISC;
8176 6 word shops=count_shops(&QMisc);
8177 6 word infos=count_infos(&QMisc);
8178 6 word warprings=count_warprings(&QMisc);
8179 6 word triforces=8;
8180 6 dword section_size = 0;
8181
8182 //section id
8183
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8184 {
8185 new_return(1);
8186 }
8187
8188
8189 //section version info
8190
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8191 {
8192 new_return(2);
8193 }
8194
8195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8196 {
8197 new_return(3);
8198 }
8199
8200
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8201 {
8202 12 fake_pack_writing=(writecycle==0);
8203
8204 //section size
8205
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8206 {
8207 new_return(4);
8208 }
8209
8210 12 writesize=0;
8211
8212 //shops
8213
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8214 {
8215 new_return(5);
8216 }
8217
8218
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8219 {
8220
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8221 {
8222 new_return(6);
8223 }
8224
8225
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8226 {
8227
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8228 {
8229 new_return(7);
8230 }
8231 384 }
8232
8233
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8234 {
8235
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8236 {
8237 new_return(8);
8238 }
8239 384 }
8240
8241
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8242 {
8243
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8244 {
8245 new_return(9);
8246 }
8247 384 }
8248 128 }
8249
8250 //infos
8251
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8252 {
8253 new_return(10);
8254 }
8255
8256
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8257 {
8258
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8259 {
8260 new_return(11);
8261 }
8262
8263
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8264 {
8265
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8266 {
8267 new_return(12);
8268 }
8269 384 }
8270
8271
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8272 {
8273
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8274 {
8275 new_return(13);
8276 }
8277 384 }
8278 128 }
8279
8280 //warp rings
8281
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8282 {
8283 new_return(14);
8284 }
8285
8286
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8287 {
8288
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8289 {
8290
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8291 {
8292 new_return(15);
8293 }
8294 1296 }
8295
8296
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8297 {
8298
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8299 {
8300 new_return(16);
8301 }
8302 1296 }
8303
8304
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8305 {
8306 new_return(17);
8307 }
8308 144 }
8309
8310 //triforce pieces
8311
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8312 {
8313
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8314 {
8315 new_return(18);
8316 }
8317 96 }
8318
8319 //end string
8320
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8321 {
8322 new_return(19);
8323 }
8324
8325 //V_MISC >= 8
8326
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8327 {
8328
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8329 {
8330
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8331 {
8332 new_return(20);
8333 }
8334 384 }
8335 128 }
8336 //V_MISC >= 9
8337
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8338 {
8339
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8340 new_return(21);
8341 384 }
8342
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8343 {
8344
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8345
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(QMisc.questmisc_strings[q][j],f))
8346 new_return(22);
8347 384 }
8348 //V_MISC >= 11
8349
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8350 new_return(23);
8351
8352 //V_MISC >= 12
8353
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8354 {
8355
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8356 new_return(24);
8357 3072 }
8358
8359 //V_MISC >= 13
8360
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8361 {
8362 768 bottletype* bt = &(QMisc.bottle_types[q]);
8363
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8364 new_return(25);
8365
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8366 {
8367
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8368 new_return(25);
8369
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8370 new_return(25);
8371 2304 }
8372
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8373 new_return(25);
8374
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8375 new_return(25);
8376 768 }
8377
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8378 {
8379 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8380
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8381 new_return(26);
8382
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8383 {
8384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8385 new_return(26);
8386
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8387 new_return(26);
8388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8389 new_return(26);
8390
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8391 new_return(26);
8392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8393 new_return(26);
8394 9216 }
8395 3072 }
8396
8397 //V_MISC >= 14
8398
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8399 {
8400
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8401 new_return(27);
8402 3072 }
8403
8404
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8405 {
8406 6 section_size=writesize;
8407 6 }
8408 12 }
8409
8410
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8411 {
8412 char ebuf[80];
8413 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8414 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8415 }
8416
8417 6 new_return(0);
8418 }
8419
8420 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8421 {
8422 //these are here to bypass compiler warnings about unused arguments
8423 6 Header=Header;
8424
8425 6 dword section_id=ID_ITEMS;
8426 6 dword section_version=V_ITEMS;
8427 6 dword section_cversion=CV_ITEMS;
8428 // dword section_size=0;
8429 6 dword section_size = 0;
8430
8431 //section id
8432
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8433 {
8434 new_return(1);
8435 }
8436
8437 //section version info
8438
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8439 {
8440 new_return(2);
8441 }
8442
8443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8444 {
8445 new_return(3);
8446 }
8447
8448
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8449 {
8450 12 fake_pack_writing=(writecycle==0);
8451
8452 //section size
8453
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8454 {
8455 new_return(4);
8456 }
8457
8458 12 writesize=0;
8459
8460 //finally... section data
8461
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8462 {
8463 new_return(5);
8464 }
8465
8466
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8467 {
8468
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8469 {
8470 new_return(5);
8471 }
8472 3072 }
8473
8474
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8475 {
8476
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8477 {
8478 new_return(6);
8479 }
8480
8481
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8482 {
8483 new_return(7);
8484 }
8485
8486
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8487 {
8488 new_return(8);
8489 }
8490
8491
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8492 {
8493 new_return(9);
8494 }
8495
8496
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8497 {
8498 new_return(10);
8499 }
8500
8501
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8502 {
8503 new_return(11);
8504 }
8505
8506
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8507 {
8508 new_return(12);
8509 }
8510
8511
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8512 {
8513 new_return(13);
8514 }
8515
8516
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8517 {
8518 new_return(14);
8519 }
8520
8521
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8522 {
8523 new_return(14);
8524 }
8525
8526
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8527 {
8528 new_return(15);
8529 }
8530
8531
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8532 {
8533 new_return(16);
8534 }
8535
8536
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8537 {
8538 new_return(17);
8539 }
8540
8541
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8542 {
8543 new_return(18);
8544 }
8545
8546
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8547 {
8548 new_return(19);
8549 }
8550
8551
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8552 {
8553 new_return(21);
8554 }
8555
8556
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8557 {
8558 new_return(22);
8559 }
8560
8561
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8562 {
8563 new_return(23);
8564 }
8565
8566
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8567 {
8568
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8569 {
8570 new_return(24);
8571 }
8572 24576 }
8573
8574
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8575 {
8576
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8577 {
8578 new_return(25);
8579 }
8580 6144 }
8581
8582
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8583 {
8584 new_return(26);
8585 }
8586
8587
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8588 {
8589 new_return(27);
8590 }
8591
8592
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8593 {
8594 new_return(28);
8595 }
8596
8597
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8598 {
8599 new_return(29);
8600 }
8601
8602
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8603 {
8604 new_return(30);
8605 }
8606
8607
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8608 {
8609 new_return(31);
8610 }
8611
8612
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8613 {
8614 new_return(32);
8615 }
8616
8617
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8618 {
8619 new_return(33);
8620 }
8621
8622
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8623 {
8624 new_return(34);
8625 }
8626
8627
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8628 {
8629 new_return(35);
8630 }
8631
8632
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8633 {
8634 new_return(36);
8635 }
8636
8637
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8638 {
8639 new_return(37);
8640 }
8641
8642
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8643 {
8644 new_return(38);
8645 }
8646
8647
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8648 {
8649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8650 {
8651 new_return(39);
8652 }
8653 6144 }
8654
8655
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8656 {
8657 new_return(40);
8658 }
8659
8660
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8661 {
8662 new_return(41);
8663 }
8664
8665
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8666 {
8667 new_return(42);
8668 }
8669
8670
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8671 {
8672 new_return(43);
8673 }
8674
8675
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8676 {
8677 new_return(44);
8678 }
8679
8680
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8681 {
8682 new_return(45);
8683 }
8684
8685
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8686 {
8687 new_return(46);
8688 }
8689
8690
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8691 {
8692 new_return(47);
8693 }
8694
8695
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8696 {
8697 new_return(48);
8698 }
8699
8700
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8701 {
8702 new_return(48);
8703 }
8704
8705 //New itemdata vars -Z
8706 //! version 27
8707
8708
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8709 {
8710 new_return(49);
8711 }
8712
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8713 {
8714 new_return(50);
8715 }
8716
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8717 {
8718 new_return(51);
8719 }
8720
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8721 {
8722 new_return(52);
8723 }
8724
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8725
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8726 {
8727 new_return(53);
8728 }
8729 30720 }
8730 //version 28
8731
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8732 {
8733 new_return(54);
8734 }
8735
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8736 {
8737
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8738 {
8739 new_return(55);
8740 }
8741 24576 }
8742
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8743 {
8744
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8745 {
8746 new_return(56);
8747 }
8748 6144 }
8749
8750
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8751 {
8752 new_return(57);
8753 }
8754
8755
8756
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8757 {
8758 new_return(58);
8759 }
8760
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8761 {
8762 new_return(59);
8763 }
8764
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8765 {
8766 new_return(60);
8767 }
8768
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8769 {
8770 new_return(61);
8771 }
8772
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8773 {
8774 new_return(62);
8775 }
8776
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8777 {
8778 new_return(63);
8779 }
8780
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8781 {
8782 new_return(64);
8783 }
8784
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8785 {
8786 new_return(65);
8787 }
8788
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8789 {
8790 new_return(66);
8791 }
8792
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8793 {
8794 new_return(67);
8795 }
8796
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8797 {
8798 new_return(68);
8799 }
8800
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8801 {
8802 new_return(69);
8803 }
8804
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8805 {
8806 new_return(70);
8807 }
8808
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8809 {
8810 new_return(71);
8811 }
8812
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8813 {
8814 new_return(72);
8815 }
8816
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8817 {
8818 new_return(73);
8819 }
8820
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8821 {
8822
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8823 {
8824 new_return(74);
8825 }
8826 6144 }
8827
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8828 {
8829 new_return(75);
8830 }
8831
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8832 {
8833 new_return(76);
8834 }
8835
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8836 {
8837 new_return(77);
8838 }
8839
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8840 {
8841 new_return(78);
8842 }
8843
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8844 {
8845 new_return(79);
8846 }
8847
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8848 {
8849 new_return(80);
8850 }
8851
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8852 {
8853 new_return(81);
8854 }
8855
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8856 {
8857 new_return(82);
8858 }
8859
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8860 {
8861 new_return(83);
8862 }
8863
8864
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8865 {
8866
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8867 {
8868 new_return(84);
8869 }
8870 6144 }
8871
8872 //InitD[] labels
8873
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8874 {
8875
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8876 {
8877
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8878 {
8879 new_return(85);
8880 }
8881 1597440 }
8882
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8883 {
8884
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8885 {
8886 new_return(86);
8887 }
8888 1597440 }
8889
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8890 {
8891
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8892 {
8893 new_return(87);
8894 }
8895 1597440 }
8896
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8897 {
8898 new_return(88);
8899 }
8900 24576 }
8901
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8902 {
8903
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8904 {
8905 new_return(89);
8906 }
8907
8908 6144 }
8909
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8910 {
8911 new_return(90);
8912 }
8913
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8914 {
8915 new_return(91);
8916 }
8917
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8918
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8919 new_return(92);
8920
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < BURNSPR_MAX; ++q)
8921 {
8922
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8923 new_return(93);
8924
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8925 new_return(94);
8926 15360 }
8927 3072 }
8928
8929
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8930 {
8931 6 section_size=writesize;
8932 6 }
8933 12 }
8934
8935
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8936 {
8937 char ebuf[80];
8938 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8939 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8940 }
8941
8942 6 new_return(0);
8943 }
8944
8945 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8946 {
8947 //these are here to bypass compiler warnings about unused arguments
8948 6 Header=Header;
8949
8950 6 dword section_id=ID_WEAPONS;
8951 6 dword section_version=V_WEAPONS;
8952 6 dword section_cversion=CV_WEAPONS;
8953 6 dword section_size = 0;
8954
8955 //section id
8956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8957 {
8958 new_return(1);
8959 }
8960
8961 //section version info
8962
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8963 {
8964 new_return(2);
8965 }
8966
8967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8968 {
8969 new_return(3);
8970 }
8971
8972
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8973 {
8974 12 fake_pack_writing=(writecycle==0);
8975
8976 //section size
8977
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8978 {
8979 new_return(4);
8980 }
8981
8982 12 writesize=0;
8983
8984 //finally... section data
8985
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8986 {
8987 new_return(5);
8988 }
8989
8990
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8991 {
8992
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8993 {
8994 new_return(5);
8995 }
8996 3072 }
8997
8998
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8999 {
9000
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
9001 {
9002 new_return(7);
9003 }
9004
9005
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
9006 {
9007 new_return(8);
9008 }
9009
9010
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
9011 {
9012 new_return(9);
9013 }
9014
9015
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
9016 {
9017 new_return(10);
9018 }
9019
9020
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
9021 {
9022 new_return(11);
9023 }
9024
9025
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
9026 {
9027 new_return(12);
9028 }
9029
9030
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
9031 {
9032 new_return(12);
9033 }
9034 3072 }
9035
9036
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9037 {
9038 6 section_size=writesize;
9039 6 }
9040 12 }
9041
9042
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9043 {
9044 char ebuf[80];
9045 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9046 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9047 }
9048
9049 6 new_return(0);
9050 }
9051
9052 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
9053 {
9054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9055 return qe_invalid;
9056
9057 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9058 4080 bool is_0x80_screen = j >= 0x80;
9059
9060
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
9061 return qe_invalid;
9062
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
9063 1998 return qe_OK;
9064 //Calculate what needs writing
9065 2082 uint32_t scr_has_flags = 0;
9066
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
9067
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
9068 2082 scr_has_flags |= SCRHAS_ROOMDATA;
9069
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
9070 290 scr_has_flags |= SCRHAS_ITEM;
9071
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
9072 18 scr_has_flags |= SCRHAS_TWARP;
9073
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
9074 {
9075
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
9076
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
9077
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
9078 {
9079 168 scr_has_flags |= SCRHAS_TWARP;
9080 168 break;
9081 }
9082 7586 }
9083
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
9084
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
9085 6 scr_has_flags |= SCRHAS_SWARP;
9086
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
9087 {
9088
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
9089
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
9090
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
9091 {
9092 1440 scr_has_flags |= SCRHAS_SWARP;
9093 1440 break;
9094 }
9095 2544 }
9096
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
9097 44 scr_has_flags |= SCRHAS_WARPRET;
9098
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
9099 {
9100
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
9101 {
9102 588 scr_has_flags |= SCRHAS_WARPRET;
9103 588 break;
9104 }
9105 5800 }
9106
9107
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
9108 scr_has_flags |= SCRHAS_LAYERS;
9109
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
9110 {
9111
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
9112
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
9113 {
9114 192 scr_has_flags |= SCRHAS_LAYERS;
9115 192 break;
9116 }
9117 11356 }
9118
9119
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(screen.exitdir)
9120 4 scr_has_flags |= SCRHAS_MAZE;
9121
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9122 {
9123
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9124 {
9125 scr_has_flags |= SCRHAS_MAZE;
9126 break;
9127 }
9128 8312 }
9129
9130
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9131
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9132
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9133 1330 scr_has_flags |= SCRHAS_D_S_U;
9134
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9135 {
9136
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9137 {
9138 732 scr_has_flags |= SCRHAS_D_S_U;
9139 732 break;
9140 }
9141 80 }
9142
9143
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9144
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9145
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9146
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9147
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9148
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9149 2082 scr_has_flags |= SCRHAS_FLAGS;
9150
9151
2/2
✓ Branch 0 taken 2032 times.
✓ Branch 1 taken 50 times.
2082 if(screen.pattern)
9152 50 scr_has_flags |= SCRHAS_ENEMY;
9153
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9154 {
9155
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9156 {
9157 640 scr_has_flags |= SCRHAS_ENEMY;
9158 640 break;
9159 }
9160 13920 }
9161
9162
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9163
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9164 6 scr_has_flags |= SCRHAS_CARRY;
9165
9166
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9167 18 scr_has_flags |= SCRHAS_SCRIPT;
9168
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9169 {
9170
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9171 {
9172 scr_has_flags |= SCRHAS_SCRIPT;
9173 break;
9174 }
9175 16512 }
9176
9177
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 20820 times.
22902 for(auto q = 0; q < 10; ++q)
9178 {
9179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20820 times.
41640 if(screen.npcstrings[q]
9180
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_items[q]
9181
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_x[q]
9182
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_y[q])
9183 {
9184 scr_has_flags |= SCRHAS_UNUSED;
9185 break;
9186 }
9187 20820 }
9188
9189
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9190 {
9191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98028 times.
197380 if(screen.secretcombo[q]
9192
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9193
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9194 {
9195 1324 scr_has_flags |= SCRHAS_SECRETS;
9196 1324 break;
9197 }
9198 98028 }
9199
9200
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9201 {
9202
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 38318 times.
40228 if(screen.data[q] || screen.cset[q]
9203
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9204 {
9205 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9206 1910 break;
9207 }
9208 38318 }
9209
9210
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9211
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9212
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9213 || screen.timedwarptics || screen.screen_midi != -1
9214 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9215 2082 scr_has_flags |= SCRHAS_MISC;
9216
9217
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9218 return qe_invalid;
9219
9220 //Write stuff
9221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9222 {
9223
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9224 return qe_invalid;
9225
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9226 return qe_invalid;
9227
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9228 return qe_invalid;
9229
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9230 return qe_invalid;
9231
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9232 return qe_invalid;
9233
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9234 return qe_invalid;
9235
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9236 return qe_invalid;
9237 2082 }
9238
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9239 {
9240
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9241 return qe_invalid;
9242
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9243 return qe_invalid;
9244
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9245 return qe_invalid;
9246
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9247 return qe_invalid;
9248 290 }
9249
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9250 {
9251
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9252 return qe_invalid;
9253 1500 }
9254
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9255 {
9256
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9257 {
9258
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9259 return qe_invalid;
9260 744 }
9261
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9262 {
9263
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9264 return qe_invalid;
9265 744 }
9266
9267
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9268 {
9269
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9270 return qe_invalid;
9271 744 }
9272
9273
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9274 return qe_invalid;
9275 186 }
9276
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9277 {
9278
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9279 {
9280
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9281 return qe_invalid;
9282 5784 }
9283
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9284 {
9285
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9286 return qe_invalid;
9287 5784 }
9288
9289
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9290 {
9291
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9292 return qe_invalid;
9293 5784 }
9294
9295
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9296 return qe_invalid;
9297
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9298 return qe_invalid;
9299 1446 }
9300
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9301 {
9302
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9303 {
9304
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9305 return qe_invalid;
9306 2528 }
9307
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9308 {
9309
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9310 return qe_invalid;
9311 2528 }
9312
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9313 return qe_invalid;
9314
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9315 return qe_invalid;
9316 632 }
9317
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9318 {
9319
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9320 {
9321
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9322 return qe_invalid;
9323 1152 }
9324
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9325 {
9326
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9327 return qe_invalid;
9328 1152 }
9329
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9330 {
9331
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9332 return qe_invalid;
9333 1152 }
9334
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9335 return qe_invalid;
9336
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9337 return qe_invalid;
9338 192 }
9339
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9340 {
9341
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9342 {
9343
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9344 return qe_invalid;
9345 16 }
9346
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9347 return qe_invalid;
9348 4 }
9349
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9350 {
9351
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9352 return qe_invalid;
9353
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9354 {
9355
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9356 return qe_invalid;
9357 8248 }
9358
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9359 return qe_invalid;
9360
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9361 return qe_invalid;
9362
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9363 return qe_invalid;
9364
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9365 return qe_invalid;
9366 2062 }
9367
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9368 {
9369
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9370 return qe_invalid;
9371
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9372 return qe_invalid;
9373
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9374 return qe_invalid;
9375
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9376 return qe_invalid;
9377
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9378 return qe_invalid;
9379
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9380 return qe_invalid;
9381
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9382 return qe_invalid;
9383
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9384 return qe_invalid;
9385
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9386 return qe_invalid;
9387
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9388 return qe_invalid;
9389
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9390 return qe_invalid;
9391 746 }
9392
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9393 {
9394
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9395 {
9396
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9397 return qe_invalid;
9398 6900 }
9399
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9400 return qe_invalid;
9401 690 }
9402
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9403 {
9404
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9405 return qe_invalid;
9406
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9407 return qe_invalid;
9408
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9409 return qe_invalid;
9410
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9411 return qe_invalid;
9412 6 }
9413
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9414 {
9415
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9416 return qe_invalid;
9417
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9418 return qe_invalid;
9419
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9420 {
9421
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9422 return qe_invalid;
9423 144 }
9424 18 }
9425
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(scr_has_flags & SCRHAS_UNUSED)
9426 {
9427 for ( int32_t q = 0; q < 10; q++ )
9428 {
9429 if(!p_iputl(screen.npcstrings[q],f))
9430 return qe_invalid;
9431 }
9432 for ( int32_t q = 0; q < 10; q++ )
9433 {
9434 if(!p_iputw(screen.new_items[q],f))
9435 return qe_invalid;
9436 }
9437 for ( int32_t q = 0; q < 10; q++ )
9438 {
9439 if(!p_iputw(screen.new_item_x[q],f))
9440 return qe_invalid;
9441 }
9442 for ( int32_t q = 0; q < 10; q++ )
9443 {
9444 if(!p_iputw(screen.new_item_y[q],f))
9445 return qe_invalid;
9446 }
9447 }
9448
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9449 {
9450
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9451 {
9452
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9453 return qe_invalid;
9454 169472 }
9455
9456
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9457 {
9458
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9459 return qe_invalid;
9460 169472 }
9461
9462
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9463 {
9464
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9465 return qe_invalid;
9466 169472 }
9467 1324 }
9468
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9469 {
9470
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9471 {
9472
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9473 return qe_invalid;
9474 336160 }
9475
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9476 {
9477
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9478 return qe_invalid;
9479 336160 }
9480
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9481 {
9482
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9483 return qe_invalid;
9484 336160 }
9485 1910 }
9486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9487 {
9488
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9489 return qe_invalid;
9490
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9491 return qe_invalid;
9492
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9493 return qe_invalid;
9494
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9495 return qe_invalid;
9496
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9497 return qe_invalid;
9498
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9499 return qe_invalid;
9500
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9501 return qe_invalid;
9502
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9503 return qe_invalid;
9504
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9505 return qe_invalid;
9506
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9507 return qe_invalid;
9508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(!p_putc(screen.lens_hide,f))
9509 return qe_invalid;
9510 2082 }
9511
9512 2082 dword numffc = screen.numFFC();
9513
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9514 return qe_invalid;
9515
2/2
✓ Branch 0 taken 45816 times.
✓ Branch 1 taken 2082 times.
47898 for(int32_t k=0; k<numffc; ++k)
9516 {
9517 45816 ffcdata const& tempffc = screen.ffcs[k];
9518
9519
1/2
✓ Branch 0 taken 45816 times.
✗ Branch 1 not taken.
45816 if(!p_iputw(tempffc.data,f))
9520 return qe_invalid;
9521
9522
2/2
✓ Branch 0 taken 44726 times.
✓ Branch 1 taken 1090 times.
45816 if(!tempffc.data) //don't save the rest of the ffc
9523 44726 continue;
9524
9525
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9526 return qe_invalid;
9527
9528
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9529 return qe_invalid;
9530
9531
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9532 return qe_invalid;
9533
9534
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9535 return qe_invalid;
9536
9537
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9538 return qe_invalid;
9539
9540
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9541 return qe_invalid;
9542
9543
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9544 return qe_invalid;
9545
9546
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9547 return qe_invalid;
9548
9549
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9550 return qe_invalid;
9551
9552
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9553 return qe_invalid;
9554
9555
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9556 return qe_invalid;
9557
9558
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9559 return qe_invalid;
9560
9561
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9562 return qe_invalid;
9563
9564
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9565 return qe_invalid;
9566
9567
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9568 return qe_invalid;
9569
9570
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9571 {
9572
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9573 return qe_invalid;
9574 8720 }
9575
9576
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9577 return qe_invalid;
9578
9579
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9580 return qe_invalid;
9581 1090 }
9582
9583
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9584 return qe_invalid;
9585
9586 2082 return qe_OK;
9587 4080 }
9588
9589 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9590 {
9591 6 dword section_id=ID_MAPS;
9592 6 dword section_version=V_MAPS;
9593 6 dword section_cversion=CV_MAPS;
9594 6 dword section_size = 0;
9595
9596 //section id
9597
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9598 {
9599 new_return(1);
9600 }
9601
9602 //section version info
9603
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9604 {
9605 new_return(2);
9606 }
9607
9608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9609 {
9610 new_return(3);
9611 }
9612
9613
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9614 {
9615 12 fake_pack_writing=(writecycle==0);
9616
9617 //section size
9618
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9619 {
9620 new_return(4);
9621 }
9622
9623 12 writesize=0;
9624
9625
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9626 {
9627 new_return(5);
9628 }
9629 12 map_autolayers.resize(map_count*6);
9630
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9631 {
9632 30 byte valid = 0;
9633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9634 {
9635
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9636 break;
9637 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9638
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9639 {
9640 30 valid = 1;
9641 30 break;
9642 }
9643 210 }
9644
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9645 {
9646 new_return(6);
9647 }
9648
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9649
9650 { //per-map info
9651
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9652 {
9653 180 size_t ind = i*6+q;
9654
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9655 new_return(7);
9656 180 }
9657 }
9658
9659
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9660 4080 writemapscreen(f,i,j);
9661 30 }
9662
9663
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9664 {
9665 6 section_size=writesize;
9666 6 }
9667 12 }
9668
9669
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9670 {
9671 char ebuf[80];
9672 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9673 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9674 }
9675
9676 6 new_return(0);
9677 }
9678
9679 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9680 {
9681 //Check what needs writing
9682 byte combo_has_flags = 0;
9683 383638 for(auto q = 0; q < 8; ++q)
9684 {
9685 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9686 383638 || (q < 4 && tmp_cmb.attributes[q]))
9687 {
9688 combo_has_flags |= CHAS_ATTRIB;
9689 break;
9690 }
9691 383638 }
9692
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9693
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9694
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9695
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9696
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9697
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9698
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9699
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9700
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9701
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9702
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9703
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9704
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9705
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9706
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9707
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9708
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9709
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9710
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9711
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9712
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9713
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9714
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9715
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9716 96892 combo_has_flags |= CHAS_TRIG;
9717
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9718
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9719 combo_has_flags |= CHAS_TRIG;
9720
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9721 193592 combo_has_flags |= CHAS_FLAG;
9722
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9723
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9724
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9725 196334 combo_has_flags |= CHAS_ANIM;
9726
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9727 70224 combo_has_flags |= CHAS_SCRIPT;
9728
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9729 {
9730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9731 {
9732 combo_has_flags |= CHAS_SCRIPT;
9733 break;
9734 }
9735 776032 }
9736
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9737
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9738 185268 combo_has_flags |= CHAS_BASIC;
9739
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9740
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9741
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9742
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9743
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9744
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9745
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9746 131132 combo_has_flags |= CHAS_LIFT;
9747
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9748
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9749
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9750 131132 combo_has_flags |= CHAS_GENERAL;
9751
9752
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9753 {
9754 34128 return 50;
9755 }
9756
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9757 //Write the combo
9758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9759 {
9760
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9761 return 6;
9762
9763
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9764 return 7;
9765
9766
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9767 return 8;
9768
9769
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9770 return 9;
9771
9772
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9773 return 15;
9774
9775
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9776 return 10;
9777 44820 }
9778
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9779 {
9780 p_putcstr(tmp_cmb.label, f);
9781
9782 if(!p_iputw(tmp_cmb.script,f))
9783 return 26;
9784 for ( int32_t q = 0; q < 8; q++ )
9785 if(!p_iputl(tmp_cmb.initd[q],f))
9786 return 27;
9787 }
9788
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9789 {
9790
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9791 return 11;
9792
9793
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9794 return 12;
9795
9796
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9797 return 13;
9798
9799
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9800 return 14;
9801
9802
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9803 return 16;
9804
9805
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9806 return 18;
9807
9808
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9809 return 19;
9810 17346 }
9811
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9812 {
9813
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9815 return 20;
9816
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9818 return 25;
9819
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9821 return 32;
9822 2268 }
9823
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9824 {
9825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9826 return 21;
9827
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9828 return 33;
9829 184 }
9830
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9831 {
9832
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9834 return 22;
9835
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9836 return 23;
9837
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9838 return 34;
9839
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9840 return 35;
9841
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9842 return 36;
9843
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9844 return 37;
9845
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9846 return 38;
9847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9848 return 39;
9849
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9850 return 40;
9851
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9852 return 41;
9853
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9854 return 42;
9855
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9856 return 43;
9857
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9858 return 44;
9859
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9860 return 45;
9861
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9862 return 46;
9863
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9864 return 47;
9865
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9866 return 48;
9867
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9868 return 49;
9869
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9870 return 50;
9871
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9872 return 51;
9873
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9874 return 52;
9875
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9876 return 53;
9877
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9878 return 69;
9879
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9880 return 70;
9881
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9882 return 71;
9883
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9884 return 72;
9885
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9886 return 76;
9887
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9888 return 77;
9889
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9890 return 89;
9891
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9892 return 90;
9893
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9894 return 91;
9895
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9896 return 92;
9897
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9898
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_iputw(tmp_cmb.trigtint[q],f))
9899 return 93;
9900
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9901 return 94;
9902
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9903 return 95;
9904
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9905 return 96;
9906
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9907 return 97;
9908
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9909 return 98;
9910
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9911 return 99;
9912
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9913 return 100;
9914
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9915 return 101;
9916
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9917 return 102;
9918
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9919 return 103;
9920 168 }
9921
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9922 {
9923
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9924 return 54;
9925
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9926 return 55;
9927
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9928 return 56;
9929
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9930 return 57;
9931
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9932 return 58;
9933
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9934 return 59;
9935
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9936 return 60;
9937
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9938 return 61;
9939
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9940 return 62;
9941
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9942 return 63;
9943
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9944 return 64;
9945
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9946 return 65;
9947
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9948 return 66;
9949
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9950 return 67;
9951
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9952 return 68;
9953
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9954 return 78;
9955 8 }
9956
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9957 {
9958
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9959 return 73;
9960
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9961 return 74;
9962
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9963 return 75;
9964
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9965 return 79;
9966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9967 return 80;
9968
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9969 return 81;
9970
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9971 return 82;
9972
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9973 return 83;
9974
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9975 return 84;
9976
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9977 return 85;
9978
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9979 return 86;
9980
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9981 return 87;
9982
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9983 return 88;
9984 8 }
9985 44820 return 0;
9986 131132 }
9987
9988 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9989 {
9990 //these are here to bypass compiler warnings about unused arguments
9991 6 version=version;
9992 6 build=build;
9993
9994 word combos_used;
9995 6 dword section_id=ID_COMBOS;
9996 6 dword section_version=V_COMBOS;
9997 6 dword section_cversion=CV_COMBOS;
9998 // dword section_size=0;
9999 6 combos_used = count_combos()-start_combo;
10000
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
10001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
10002 6 dword section_size = 0;
10003
10004 //section id
10005
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10006 {
10007 new_return(1);
10008 }
10009
10010 //section version info
10011
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10012 {
10013 new_return(2);
10014 }
10015
10016
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
10017 {
10018 new_return(3);
10019 }
10020
10021
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10022 {
10023 12 fake_pack_writing=(writecycle==0);
10024
10025 //section size
10026
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10027 {
10028 new_return(4);
10029 }
10030
10031 12 writesize=0;
10032
10033 //finally... section data
10034 12 combos_used=count_combos()-start_combo;
10035
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
10036
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
10037
10038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
10039 {
10040 new_return(5);
10041 }
10042
10043 12 size_t end_combo = start_combo+combos_used;
10044
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
10045 {
10046 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
10047
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
10048 97004 }
10049
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10050 {
10051 6 section_size=writesize;
10052 6 }
10053 12 }
10054
10055
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10056 {
10057 char ebuf[80];
10058 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10059 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10060 }
10061
10062 6 new_return(0);
10063 6 }
10064
10065 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
10066 {
10067 //these are here to bypass compiler warnings about unused arguments
10068 6 version=version;
10069 6 build=build;
10070
10071 6 dword section_id=ID_COMBOALIASES;
10072 6 dword section_version=V_COMBOALIASES;
10073 6 dword section_cversion=CV_COMBOALIASES;
10074 6 dword section_size=0;
10075
10076 //section id
10077
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10078 {
10079 new_return(1);
10080 }
10081
10082 //section version info
10083
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10084 {
10085 new_return(2);
10086 }
10087
10088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10089 {
10090 new_return(3);
10091 }
10092
10093
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10094 {
10095 12 fake_pack_writing=(writecycle==0);
10096
10097 //section size
10098
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10099 {
10100 new_return(4);
10101 }
10102
10103 12 writesize=0;
10104
10105 //finally... section data
10106
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10107 {
10108
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
10109 {
10110 new_return(5);
10111 }
10112
10113
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
10114 {
10115 new_return(6);
10116 }
10117
10118 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10119
10120
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
10121 {
10122 new_return(7);
10123 }
10124
10125
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
10126 {
10127 new_return(8);
10128 }
10129
10130
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
10131 {
10132 new_return(9);
10133 }
10134
10135
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10136 {
10137
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
10138 {
10139 new_return(10);
10140 }
10141 99792 }
10142
10143
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10144 {
10145
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10146 {
10147 new_return(11);
10148 }
10149 99792 }
10150 98304 }
10151
10152 //Combo pools!
10153 int16_t num_cpools;
10154
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10155 {
10156
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10157 {
10158 2 ++num_cpools;
10159 2 break;
10160 }
10161 98298 }
10162
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10163
10164
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10165 {
10166 new_return(12);
10167 }
10168
10169
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10170 {
10171 6 combo_pool const& pool = combo_pools[cp];
10172 6 int32_t num_combos = pool.combos.size();
10173
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10174 {
10175 new_return(13);
10176 }
10177
10178
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10179 {
10180 26 cpool_entry const& entry = pool.combos.at(q);
10181
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10182 {
10183 new_return(14);
10184 }
10185
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10186 {
10187 new_return(15);
10188 }
10189
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10190 {
10191 new_return(16);
10192 }
10193 26 }
10194 6 }
10195
10196 //Autocombos!
10197 int16_t num_cautos;
10198
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10199 {
10200
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10201 {
10202 ++num_cautos;
10203 break;
10204 }
10205 98304 }
10206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10207
10208
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10209 {
10210 new_return(17);
10211 }
10212
10213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10214 {
10215 combo_auto const& cauto = combo_autos[ca];
10216 if (!p_putc(cauto.getType(), f))
10217 {
10218 new_return(18);
10219 }
10220 if (!p_iputl(cauto.getIconDisplay(), f))
10221 {
10222 new_return(19);
10223 }
10224 if (!p_iputl(cauto.getEraseCombo(), f))
10225 {
10226 new_return(20);
10227 }
10228 if (!p_putc(cauto.getFlags(), f))
10229 {
10230 new_return(21);
10231 }
10232 if (!p_putc(cauto.getArg(), f))
10233 {
10234 new_return(22);
10235 }
10236 int32_t num_combos = cauto.combos.size();
10237 if (!p_iputl(num_combos, f))
10238 {
10239 new_return(23);
10240 }
10241
10242 for (auto q = 0; q < num_combos; ++q)
10243 {
10244 autocombo_entry const& entry = cauto.combos.at(q);
10245 if (!p_putc(entry.ctype, f))
10246 {
10247 new_return(24);
10248 }
10249 if (!p_iputl(entry.cid, f))
10250 {
10251 new_return(25);
10252 }
10253 }
10254 }
10255
10256
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10257 {
10258 6 section_size=writesize;
10259 6 }
10260 12 }
10261
10262
10263
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10264 {
10265 char ebuf[80];
10266 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10267 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10268 }
10269
10270 6 new_return(0);
10271 }
10272
10273 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10274 {
10275 //these are here to bypass compiler warnings about unused arguments
10276 6 version=version;
10277 6 build=build;
10278 6 start_cset=start_cset;
10279 6 max_csets=max_csets;
10280
10281 6 dword section_id=ID_CSETS;
10282 6 dword section_version=V_CSETS;
10283 6 dword section_cversion=CV_CSETS;
10284 6 int32_t palcycles = count_palcycles(&QMisc);
10285 // int32_t palcyccount = count_palcycles(&QMisc);
10286 6 dword section_size = 0;
10287
10288 //section id
10289
10290
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10291 {
10292 new_return(1);
10293 }
10294
10295 //section version info
10296
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10297 {
10298 new_return(2);
10299 }
10300
10301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10302 {
10303 new_return(3);
10304 }
10305
10306
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10307 {
10308 12 fake_pack_writing=(writecycle==0);
10309
10310 //section size
10311
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10312 {
10313 new_return(4);
10314 }
10315
10316 12 writesize=0;
10317
10318 //finally... section data
10319
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10320 {
10321 new_return(5);
10322 }
10323
10324
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10325 {
10326 new_return(6);
10327 }
10328
10329
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10330 {
10331 new_return(15);
10332 }
10333
10334
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10335 {
10336
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10337 {
10338
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10339 {
10340 new_return(16);
10341 }
10342 828 }
10343
10344
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10345 {
10346
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10347 {
10348 new_return(17);
10349 }
10350 828 }
10351
10352
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10353 {
10354
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10355 {
10356 new_return(18);
10357 }
10358 828 }
10359 276 }
10360
10361
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10362 {
10363 6 section_size=writesize;
10364 6 }
10365 12 }
10366
10367
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10368 {
10369 char ebuf[80];
10370 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10371 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10372 }
10373
10374 6 new_return(0);
10375 }
10376
10377 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10378 {
10379 //these are here to bypass compiler warnings about unused arguments
10380 6 version=version;
10381 6 build=build;
10382 6 start_msgstr=start_msgstr;
10383 6 max_msgstrs=max_msgstrs;
10384
10385 6 dword section_id=ID_STRINGS;
10386 6 dword section_version=V_STRINGS;
10387 6 dword section_cversion=CV_STRINGS;
10388 6 dword section_size = 0;
10389
10390 //section id
10391
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10392 {
10393 new_return(1);
10394 }
10395
10396 //section version info
10397
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10398 {
10399 new_return(2);
10400 }
10401
10402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10403 {
10404 new_return(3);
10405 }
10406
10407
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10408 {
10409 12 fake_pack_writing=(writecycle==0);
10410
10411 //section size
10412
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10413 {
10414 new_return(4);
10415 }
10416
10417 12 writesize=0;
10418
10419 //finally... section data
10420
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10421 {
10422 return qe_invalid;
10423 }
10424
10425
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10426 {
10427 302 int32_t sz = MsgStrings[i].s.size();
10428
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10429
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10430 {
10431 return qe_invalid;
10432 }
10433
10434 302 char const* tmpstr = MsgStrings[i].s.c_str();
10435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10436 {
10437
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10438 {
10439 return qe_invalid;
10440 }
10441 302 }
10442
10443
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10444 {
10445 return qe_invalid;
10446 }
10447
10448
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10449 {
10450 return qe_invalid;
10451 }
10452
10453
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10454 {
10455 return qe_invalid;
10456 }
10457
10458
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10459 {
10460 return qe_invalid;
10461 }
10462
10463
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10464 {
10465 return qe_invalid;
10466 }
10467
10468
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10469 {
10470 return qe_invalid;
10471 }
10472
10473
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10474 {
10475 return qe_invalid;
10476 }
10477
10478
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10479 {
10480 return qe_invalid;
10481 }
10482
10483
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10484 {
10485 return qe_invalid;
10486 }
10487
10488
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10489 {
10490 return qe_invalid;
10491 }
10492
10493
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10494 {
10495 return qe_invalid;
10496 }
10497
10498
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10499 {
10500 return qe_invalid;
10501 }
10502
10503
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10504 {
10505
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10506 {
10507 return qe_invalid;
10508 }
10509 1208 }
10510
10511
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10512 {
10513 return qe_invalid;
10514 }
10515
10516
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10517 {
10518 return qe_invalid;
10519 }
10520
10521
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10522 {
10523 return qe_invalid;
10524 }
10525
10526
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10527 {
10528 return qe_invalid;
10529 }
10530
10531
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10532 {
10533 return qe_invalid;
10534 }
10535
10536
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10537 {
10538 return qe_invalid;
10539 }
10540
10541
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10542 {
10543 return qe_invalid;
10544 }
10545
10546
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10547 {
10548 return qe_invalid;
10549 }
10550
10551
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10552 {
10553 return qe_invalid;
10554 }
10555
10556
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10557 {
10558 return qe_invalid;
10559 }
10560
10561
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10562 {
10563 return qe_invalid;
10564 }
10565 302 }
10566
10567
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10568 {
10569 6 section_size=writesize;
10570 6 }
10571 12 }
10572
10573
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10574 {
10575 char ebuf[80];
10576 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10577 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10578 }
10579
10580 6 new_return(0);
10581 6 }
10582
10583 int32_t writestrings_text(PACKFILE *f)
10584 {
10585 std::map<int32_t, int32_t> msglistcache;
10586
10587 for(int32_t index = 1; index<msg_count; index++)
10588 {
10589 for(int32_t i=1; i<msg_count; i++)
10590 {
10591 if(MsgStrings[i].listpos==index)
10592 {
10593 msglistcache[index-1]=i;
10594 break;
10595 }
10596 }
10597 }
10598
10599 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10600 {
10601 fake_pack_writing=(writecycle==0);
10602 char ebuf[32];
10603
10604 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10605
10606 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10607 {
10608 return qe_invalid;
10609 }
10610
10611 for(int32_t i=1; i<msg_count; i++)
10612 {
10613 int32_t str = msglistcache[i-1];
10614
10615 if(!str)
10616 continue;
10617
10618 if(MsgStrings[str].nextstring != 0)
10619 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10620 else
10621 sprintf(ebuf,"\n\n___%d___\n", str);
10622
10623 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10624 {
10625 return qe_invalid;
10626 }
10627
10628 encode_msg_str(str);
10629
10630 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10631 {
10632 return qe_invalid;
10633 }
10634 }
10635 }
10636
10637 new_return(0);
10638 }
10639
10640 1 int32_t writestrings_tsv(PACKFILE *f)
10641 {
10642 1 std::stringstream ss;
10643
10644 int32_t str;
10645
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10646
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10647 35 encode_msg_str(str);
10648 35 return msgbuf;
10649 }},
10650
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10651
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10652
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10653
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10654
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10655
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10656
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10657
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10658
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10659
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10660
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10661
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10662
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10663
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10664
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10666
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10667
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10668
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10669
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10670
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10671
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10672
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10673
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10674 };
10675
10676
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10677 {
10678
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10679
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10680 1 break;
10681
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10682 }
10683
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10684
10685 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10686
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10687
10688
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10689 {
10690 35 str = i;
10691 35 auto& msg = MsgStrings[str];
10692
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10693 {
10694
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10695
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10696
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10697 35 break;
10698
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10699
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10700
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10701 35 }
10702
10703
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10704
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10705 {
10706 return qe_invalid;
10707 }
10708
10709 1 new_return(0);
10710 1 }
10711
10712 std::string parse_msg_str(std::string const& s);
10713
10714 void parse_strings_tsv(std::string tsv)
10715 {
10716 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10717 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10718 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10719 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10720 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10721 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10722 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10723 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10724 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10725 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10726 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10727 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10728 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10729 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10730 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10731 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10732 { "margin", [&](auto& msg, auto& text){
10733 std::vector<std::string> strs;
10734 util::split(text, strs, ' ');
10735 if (strs.size() != 4)
10736 throw std::runtime_error("margin field must have 4 components");
10737 msg.margins[0] = std::stoi(strs[0]);
10738 msg.margins[1] = std::stoi(strs[1]);
10739 msg.margins[2] = std::stoi(strs[2]);
10740 msg.margins[3] = std::stoi(strs[3]);
10741 } },
10742 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10743 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10744 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10745 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10746 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10747 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10748 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10749 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10750 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10751 };
10752
10753 std::vector<std::string> rows;
10754 util::split(tsv, rows, '\n');
10755 if (rows.size())
10756 {
10757 std::string last = rows.back();
10758 util::trimstr(last);
10759 if (last.empty())
10760 rows.pop_back();
10761 }
10762 if (rows.size() <= 1)
10763 throw std::runtime_error("missing header row");
10764
10765 std::vector<std::string> columns;
10766 util::split(rows[0], columns, '\t');
10767 for (auto name : columns)
10768 {
10769 if (!fields.contains(name))
10770 throw std::runtime_error(fmt::format("invalid field: {}", name));
10771 }
10772
10773 int start_index = 1;
10774 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10775 start_index += 1;
10776
10777 int num_strings = rows.size() - start_index + 1;
10778 if (num_strings > MAXMSGS-1)
10779 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10780
10781 std::vector<MsgStr> msgs;
10782 msgs.reserve(num_strings);
10783 for (int i = start_index; i < rows.size(); i++)
10784 {
10785 std::vector<std::string> strs;
10786 util::split(rows[i], strs, '\t');
10787 if (strs.size() != columns.size())
10788 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10789
10790 int j = 0;
10791 auto& msg = msgs.emplace_back();
10792 for (auto& name : columns)
10793 {
10794 auto& fn = fields[name];
10795 try
10796 {
10797 fn(msg, strs[j++]);
10798 }
10799 catch (std::exception& ex)
10800 {
10801 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10802 }
10803 }
10804 }
10805
10806 init_msgstrings(0, msgs.size());
10807 for (int i = 0; i < msgs.size(); i++)
10808 MsgStrings[i + 1] = msgs[i];
10809 msg_count = msgs.size();
10810 msglistcache.clear();
10811 }
10812
10813 bool isblanktile(tiledata *buf, int32_t i);
10814 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10815 {
10816 //these are here to bypass compiler warnings about unused arguments
10817 6 version=version;
10818 6 build=build;
10819
10820 int32_t tiles_used;
10821 6 dword section_id=ID_TILES;
10822 6 dword section_version=V_TILES;
10823 6 dword section_cversion=CV_TILES;
10824 6 al_trace("Counting tiles used\n");
10825 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10826
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10827
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10828 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10829 6 dword section_size = 0;
10830
10831 //section id
10832
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10833 {
10834 new_return(1);
10835 }
10836
10837 //section version info
10838
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10839 {
10840 new_return(2);
10841 }
10842
10843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10844 {
10845 new_return(3);
10846 }
10847
10848
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10849 {
10850 12 fake_pack_writing=(writecycle==0);
10851
10852 //section size
10853
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10854 {
10855 new_return(4);
10856 }
10857
10858 12 writesize=0;
10859
10860 //finally... section data
10861 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10862
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10863
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10864
10865
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10866 {
10867 new_return(5);
10868 }
10869
10870
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10871 {
10872
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10873 {
10874
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10875 new_return(8);
10876 238750 }
10877 else
10878 {
10879 209304 int format = newtilebuf[start_tile+i].format;
10880
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10881 {
10882 new_return(6);
10883 }
10884
10885
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10886 {
10887 byte temp_tile[128];
10888 207706 byte *di = temp_tile;
10889 207706 byte *src = newtilebuf[start_tile+i].data;
10890
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10891 {
10892 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10893 26586368 ++di;
10894 26586368 }
10895
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10896 {
10897 new_return(7);
10898 }
10899 207706 }
10900
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10901 {
10902 new_return(7);
10903 }
10904 }
10905 448054 }
10906
10907
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10908 {
10909 6 section_size=writesize;
10910 6 }
10911 12 }
10912
10913
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10914 {
10915 char ebuf[80];
10916 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10917 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10918 }
10919
10920 6 new_return(0);
10921 }
10922
10923 /* MIDI Format
10924 section_id LONG
10925 section_version WORD
10926 section_cversion WORD
10927 section_size LONG
10928 midi_flags 32 Byte ? BITFIELD[252]
10929
10930 [
10931 title 36
10932 start 4
10933 loop_start 4
10934 loop_end 4
10935 loop 2
10936 volume 2
10937 midi *
10938 ]
10939
10940 */
10941
10942 6 int32_t writemidis(PACKFILE *f)
10943 {
10944 6 dword section_id=ID_MIDIS;
10945 6 dword section_version=V_MIDIS;
10946 6 dword section_cversion=CV_MIDIS;
10947 6 dword section_size = 0;
10948
10949 //section id
10950
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10951 {
10952 new_return(1);
10953 }
10954
10955 //section version info
10956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10957 {
10958 new_return(2);
10959 }
10960
10961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10962 {
10963 new_return(3);
10964 }
10965
10966
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10967 {
10968 12 fake_pack_writing=(writecycle==0);
10969
10970 //section size
10971
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10972 {
10973 new_return(4);
10974 }
10975
10976 12 writesize=0;
10977
10978 //finally... section data
10979
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10980 {
10981 new_return(5);
10982 }
10983
10984
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10985 {
10986
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10987 {
10988
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10989 {
10990 new_return(6);
10991 }
10992
10993
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10994 {
10995 new_return(7);
10996 }
10997
10998
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
10999 {
11000 new_return(8);
11001 }
11002
11003
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
11004 {
11005 new_return(9);
11006 }
11007
11008
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
11009 {
11010 new_return(10);
11011 }
11012
11013
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
11014 {
11015 new_return(11);
11016 }
11017
11018
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
11019 {
11020 new_return(12);
11021 }
11022
11023
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].format, sizeof(customtunes[i].format),f))
11024 {
11025 new_return(13);
11026 }
11027
11028
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 switch(customtunes[i].format)
11029 {
11030 case MFORMAT_MIDI:
11031
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!write_midi((MIDI*) customtunes[i].data,f)) new_return(14);
11032
11033 60 break;
11034
11035 default:
11036 new_return(15);
11037 break;
11038 }
11039 60 }
11040 3024 }
11041
11042
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11043 {
11044 6 section_size=writesize;
11045 6 }
11046 12 }
11047
11048
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11049 {
11050 char ebuf[80];
11051 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11052 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11053 }
11054
11055 6 new_return(0);
11056 }
11057
11058 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
11059 {
11060 6 dword section_id=ID_CHEATS;
11061 6 dword section_version=V_CHEATS;
11062 6 dword section_cversion=CV_CHEATS;
11063 6 dword section_size = 0;
11064
11065 //section id
11066
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11067 {
11068 new_return(1);
11069 }
11070
11071 //section version info
11072
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11073 {
11074 new_return(2);
11075 }
11076
11077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11078 {
11079 new_return(3);
11080 }
11081
11082
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11083 {
11084 12 fake_pack_writing=(writecycle==0);
11085
11086 //section size
11087
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11088 {
11089 new_return(4);
11090 }
11091
11092 12 writesize=0;
11093
11094 //finally... section data
11095
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11096 {
11097 new_return(5);
11098 }
11099
11100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
11101 {
11102
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
11103 {
11104 new_return(6);
11105 }
11106
11107
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11108 {
11109 new_return(7);
11110 }
11111 12 }
11112
11113
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11114 {
11115 6 section_size=writesize;
11116 6 }
11117 12 }
11118
11119
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11120 {
11121 char ebuf[80];
11122 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11123 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11124 }
11125
11126 6 new_return(0);
11127 }
11128
11129 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11130 {
11131 //these are here to bypass compiler warnings about unused arguments
11132 6 Header=Header;
11133
11134 6 dword section_id=ID_GUYS;
11135 6 dword section_version=V_GUYS;
11136 6 dword section_cversion=CV_GUYS;
11137 6 dword section_size=0;
11138
11139 //section id
11140
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11141 {
11142 new_return(1);
11143 }
11144
11145 //section version info
11146
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11147 {
11148 new_return(2);
11149 }
11150
11151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11152 {
11153 new_return(3);
11154 }
11155
11156
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11157 {
11158 12 fake_pack_writing=(writecycle==0);
11159
11160 //section size
11161
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11162 {
11163 new_return(4);
11164 }
11165
11166 12 writesize=0;
11167
11168 //finally... section data
11169
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11170 {
11171
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11172 {
11173 new_return(5);
11174 }
11175 6144 }
11176
11177
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6144 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11178 {
11179 6144 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11180 6144 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11181
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags1, f))
11182 {
11183 new_return(6);
11184 }
11185
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags2, f))
11186 {
11187 new_return(7);
11188 }
11189
11190
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11191 {
11192 new_return(8);
11193 }
11194
11195
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11196 {
11197 new_return(9);
11198 }
11199
11200
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11201 {
11202 new_return(10);
11203 }
11204
11205
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11206 {
11207 new_return(11);
11208 }
11209
11210
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11211 {
11212 new_return(12);
11213 }
11214
11215
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11216 {
11217 new_return(13);
11218 }
11219
11220
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11221 {
11222 new_return(14);
11223 }
11224
11225
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11226 {
11227 new_return(15);
11228 }
11229
11230
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11231 {
11232 new_return(16);
11233 }
11234
11235
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11236 {
11237 new_return(17);
11238 }
11239
11240
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11241 {
11242 new_return(18);
11243 }
11244
11245
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11246 {
11247 new_return(19);
11248 }
11249
11250
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11251 {
11252 new_return(20);
11253 }
11254
11255
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11256 {
11257 new_return(21);
11258 }
11259
11260
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11261 {
11262 new_return(22);
11263 }
11264
11265
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11266 {
11267 new_return(23);
11268 }
11269
11270
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11271 {
11272 new_return(24);
11273 }
11274
11275
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11276 {
11277 new_return(25);
11278 }
11279
11280
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11281 {
11282 new_return(26);
11283 }
11284
11285
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11286 {
11287 new_return(27);
11288 }
11289
11290
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11291 {
11292 new_return(28);
11293 }
11294
11295
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11296 {
11297 new_return(29);
11298 }
11299
11300
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11301 {
11302 new_return(30);
11303 }
11304
11305
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11306 {
11307 new_return(31);
11308 }
11309
11310
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11311 {
11312 new_return(32);
11313 }
11314
11315
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[0], f))
11316 {
11317 new_return(33);
11318 }
11319
11320
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[1],f))
11321 {
11322 new_return(34);
11323 }
11324
11325
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[2],f))
11326 {
11327 new_return(35);
11328 }
11329
11330
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[3],f))
11331 {
11332 new_return(36);
11333 }
11334
11335
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[4],f))
11336 {
11337 new_return(37);
11338 }
11339
11340
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[5],f))
11341 {
11342 new_return(38);
11343 }
11344
11345
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[6],f))
11346 {
11347 new_return(39);
11348 }
11349
11350
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[7],f))
11351 {
11352 new_return(40);
11353 }
11354
11355
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[8],f))
11356 {
11357 new_return(41);
11358 }
11359
11360
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[9],f))
11361 {
11362 new_return(42);
11363 }
11364
11365
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11366 {
11367 new_return(43);
11368 }
11369
11370
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11371 {
11372 new_return(44);
11373 }
11374
11375
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11376 {
11377 new_return(45);
11378 }
11379
11380
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11381 {
11382
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11383 {
11384 new_return(46);
11385 }
11386 116736 }
11387
11388
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11389 {
11390 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11391 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11392 //Force SFX_HIT here.
11393
11394 }
11395
11396
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11397 {
11398 new_return(47);
11399 }
11400
11401
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11402 {
11403 new_return(48);
11404 }
11405
11406
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[10],f))
11407 {
11408 new_return(49);
11409 }
11410
11411
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[11],f))
11412 {
11413 new_return(50);
11414 }
11415
11416 //New 2.6 defences
11417
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11418 {
11419
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11420 {
11421 new_return(51);
11422 }
11423 135168 }
11424
11425 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11426
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11427 {
11428 new_return(52);
11429 }
11430
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11431 {
11432 new_return(53);
11433 }
11434
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11435 {
11436 new_return(54);
11437 }
11438
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11439 {
11440 new_return(55);
11441 }
11442
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11443 {
11444 new_return(56);
11445 }
11446 // These are not fixed types, but ints, so they are safe to use here.
11447
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11448 {
11449 new_return(57);
11450 }
11451
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11452 {
11453 new_return(58);
11454 }
11455
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11456 {
11457 new_return(59);
11458 }
11459
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11460 {
11461 new_return(60);
11462 }
11463
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11464 {
11465 new_return(61);
11466 }
11467
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11468 {
11469 new_return(62);
11470 }
11471
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11472 {
11473 new_return(63);
11474 }
11475
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11476 {
11477 new_return(64);
11478 }
11479
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11480 {
11481 new_return(65);
11482 }
11483
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11484 {
11485 new_return(66);
11486 }
11487
11488
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11489 {
11490
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11491 {
11492 new_return(67);
11493 }
11494 61440 }
11495
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11496 {
11497 new_return(68);
11498 }
11499 //misc 16->31
11500
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[15],f))
11501 {
11502 new_return(69);
11503 }
11504
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[16],f))
11505 {
11506 new_return(70);
11507 }
11508
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[17],f))
11509 {
11510 new_return(71);
11511 }
11512
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[18],f))
11513 {
11514 new_return(72);
11515 }
11516
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[19],f))
11517 {
11518 new_return(73);
11519 }
11520
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[20],f))
11521 {
11522 new_return(74);
11523 }
11524
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[21],f))
11525 {
11526 new_return(75);
11527 }
11528
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[22],f))
11529 {
11530 new_return(76);
11531 }
11532
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[23],f))
11533 {
11534 new_return(77);
11535 }
11536
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[24],f))
11537 {
11538 new_return(78);
11539 }
11540
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[25],f))
11541 {
11542 new_return(79);
11543 }
11544
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[26],f))
11545 {
11546 new_return(80);
11547 }
11548
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[27],f))
11549 {
11550 new_return(81);
11551 }
11552
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[28],f))
11553 {
11554 new_return(82);
11555 }
11556
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[29],f))
11557 {
11558 new_return(83);
11559 }
11560
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[30],f))
11561 {
11562 new_return(84);
11563 }
11564
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[31],f))
11565 {
11566 new_return(85);
11567 }
11568
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11569 {
11570
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11571 {
11572 new_return(86);
11573 }
11574 196608 }
11575
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11576 {
11577
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11578 {
11579 new_return(87);
11580 }
11581 196608 }
11582
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11583 {
11584 new_return(88);
11585 }
11586
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11587 {
11588
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11589 {
11590 new_return(89);
11591 }
11592 49152 }
11593
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11594 {
11595
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11596 {
11597 new_return(90);
11598 }
11599 12288 }
11600
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11601 {
11602 new_return(91);
11603 }
11604 //somehow forgot these in the older builds -Z
11605
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[12],f))
11606 {
11607 new_return(92);
11608 }
11609
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[13],f))
11610 {
11611 new_return(93);
11612 }
11613
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[14],f))
11614 {
11615 new_return(94);
11616 }
11617
11618 //Enemy Editor InitD[] labels
11619
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11620 {
11621
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11622 {
11623
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11624 {
11625 new_return(95);
11626 }
11627 3194880 }
11628
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11629 {
11630
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11631 {
11632 new_return(96);
11633 }
11634 3194880 }
11635 49152 }
11636
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11637 {
11638 new_return(97);
11639 }
11640 //eweapon initD
11641
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11642 {
11643
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11644 {
11645 new_return(98);
11646 }
11647 49152 }
11648
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11649 new_return(99);
11650
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11651 new_return(100);
11652
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11653 new_return(101);
11654
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11655 new_return(102);
11656 6144 }
11657
11658
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11659 {
11660 6 section_size=writesize;
11661 6 }
11662 12 }
11663
11664
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11665 {
11666 char ebuf[80];
11667 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11668 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11669 }
11670
11671 6 new_return(0);
11672 }
11673
11674 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11675 {
11676 //these are here to bypass compiler warnings about unused arguments
11677 6 Header=Header;
11678
11679 6 dword section_id=ID_HEROSPRITES;
11680 6 dword section_version=V_HEROSPRITES;
11681 6 dword section_cversion=CV_HEROSPRITES;
11682 6 dword section_size=0;
11683
11684 //section id
11685
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11686 {
11687 new_return(1);
11688 }
11689
11690 //section version info
11691
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11692 {
11693 new_return(2);
11694 }
11695
11696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11697 {
11698 new_return(3);
11699 }
11700
11701
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11702 {
11703 12 fake_pack_writing=(writecycle==0);
11704
11705 //section size
11706
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11707 {
11708 new_return(4);
11709 }
11710
11711 12 writesize=0;
11712
11713 //finally... section data
11714
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11715 {
11716
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11717 {
11718 new_return(5);
11719 }
11720
11721
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11722 {
11723 new_return(5);
11724 }
11725
11726
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11727 {
11728 new_return(5);
11729 }
11730 48 }
11731
11732
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11733 {
11734
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11735 {
11736 new_return(6);
11737 }
11738
11739
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11740 {
11741 new_return(6);
11742 }
11743
11744
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11745 {
11746 new_return(6);
11747 }
11748 48 }
11749
11750
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11751 {
11752
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11753 {
11754 new_return(7);
11755 }
11756
11757
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11758 {
11759 new_return(7);
11760 }
11761
11762
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11763 {
11764 new_return(7);
11765 }
11766 48 }
11767
11768
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11769 {
11770
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11771 {
11772 new_return(8);
11773 }
11774
11775
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11776 {
11777 new_return(8);
11778 }
11779
11780
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11781 {
11782 new_return(8);
11783 }
11784 48 }
11785
11786
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11787 {
11788
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11789 {
11790 new_return(8);
11791 }
11792
11793
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11794 {
11795 new_return(8);
11796 }
11797
11798
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11799 {
11800 new_return(8);
11801 }
11802 48 }
11803
11804
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11805 {
11806
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11807 {
11808 new_return(9);
11809 }
11810
11811
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11812 {
11813 new_return(9);
11814 }
11815
11816
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11817 {
11818 new_return(9);
11819 }
11820 48 }
11821
11822
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11823 {
11824
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11825 {
11826 new_return(10);
11827 }
11828
11829
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11830 {
11831 new_return(10);
11832 }
11833
11834
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11835 {
11836 new_return(10);
11837 }
11838 48 }
11839
11840
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11841 {
11842 new_return(11);
11843 }
11844
11845
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11846 {
11847 new_return(11);
11848 }
11849
11850
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11851 {
11852 new_return(11);
11853 }
11854
11855
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11856 {
11857
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11858 {
11859
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11860 {
11861 new_return(12);
11862 }
11863
11864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11865 {
11866 new_return(12);
11867 }
11868
11869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11870 {
11871 new_return(12);
11872 }
11873 72 }
11874 24 }
11875
11876
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11877 {
11878
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11879 {
11880 new_return(13);
11881 }
11882
11883
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11884 {
11885 new_return(13);
11886 }
11887
11888
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11889 {
11890 new_return(13);
11891 }
11892 48 }
11893
11894
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11895 {
11896
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11897 {
11898 new_return(13);
11899 }
11900
11901
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11902 {
11903 new_return(13);
11904 }
11905
11906
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11907 {
11908 new_return(13);
11909 }
11910 48 }
11911
11912
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11913 {
11914 new_return(14);
11915 }
11916
11917 //{ V_HEROSPRITES >= 7
11918
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11919 {
11920
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11921 new_return(15);
11922
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11923 new_return(15);
11924
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11925 new_return(15);
11926 48 }
11927
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11928 {
11929
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11930 new_return(15);
11931
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11932 new_return(15);
11933
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11934 new_return(15);
11935 48 }
11936
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11937 {
11938
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11939 new_return(15);
11940
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11941 new_return(15);
11942
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11943 new_return(15);
11944 48 }
11945
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11946 {
11947
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11948 new_return(15);
11949
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11950 new_return(15);
11951
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11952 new_return(15);
11953 48 }
11954
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11955 {
11956
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11957 new_return(15);
11958
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11959 new_return(15);
11960
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11961 new_return(15);
11962 48 }
11963
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11964 {
11965
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11966 new_return(15);
11967
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11968 new_return(15);
11969
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11970 new_return(15);
11971 48 }
11972
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11973 {
11974
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11975 new_return(15);
11976
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11977 new_return(15);
11978
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11979 new_return(15);
11980 48 }
11981
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11982 {
11983
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11984 new_return(15);
11985
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11986 new_return(15);
11987
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11988 new_return(15);
11989 48 }
11990
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11991 {
11992
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11993 new_return(15);
11994
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11995 new_return(15);
11996
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11997 new_return(15);
11998
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11999 new_return(15);
12000 48 }
12001
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12002 {
12003
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
12004 new_return(15);
12005
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
12006 new_return(15);
12007
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
12008 new_return(15);
12009 48 }
12010
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12011 {
12012
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
12013 new_return(15);
12014
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
12015 new_return(15);
12016
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
12017 new_return(15);
12018 48 }
12019
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12020 {
12021
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
12022 new_return(15);
12023
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
12024 new_return(15);
12025
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
12026 new_return(15);
12027 48 }
12028
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12029 {
12030
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
12031 new_return(15);
12032
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
12033 new_return(15);
12034
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
12035 new_return(15);
12036 48 }
12037
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12038 {
12039
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
12040 new_return(15);
12041
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
12042 new_return(15);
12043
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
12044 new_return(15);
12045 48 }
12046
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12047 {
12048
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
12049 new_return(15);
12050
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
12051 new_return(15);
12052
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
12053 new_return(15);
12054 48 }
12055
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12056 {
12057
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
12058 new_return(15);
12059
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
12060 new_return(15);
12061
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
12062 new_return(15);
12063 48 }
12064
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12065 {
12066
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
12067 new_return(15);
12068
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
12069 new_return(15);
12070
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
12071 new_return(15);
12072 48 }
12073
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12074 {
12075
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
12076 new_return(15);
12077
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
12078 new_return(15);
12079
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
12080 new_return(15);
12081 48 }
12082
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12083 {
12084
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
12085 new_return(15);
12086
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
12087 new_return(15);
12088
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
12089 new_return(15);
12090 48 }
12091
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12092 {
12093
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
12094 new_return(15);
12095
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
12096 new_return(15);
12097
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
12098 new_return(15);
12099 48 }
12100
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12101 {
12102
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
12103 new_return(15);
12104
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
12105 new_return(15);
12106
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12107 new_return(15);
12108 48 }
12109
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12110 {
12111
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
12112 new_return(15);
12113
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
12114 new_return(15);
12115
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12116 new_return(15);
12117 48 }
12118
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12119 {
12120
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12121 new_return(15);
12122
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12123 new_return(15);
12124
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12125 new_return(15);
12126 48 }
12127
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12128 {
12129
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12130 new_return(15);
12131
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12132 new_return(15);
12133
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12134 new_return(15);
12135 36 }
12136
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12137 {
12138
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12139 new_return(16);
12140
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12141 new_return(16);
12142
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12143 new_return(16);
12144 48 }
12145
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12146 {
12147
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12148 new_return(17);
12149
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12150 new_return(17);
12151
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12152 new_return(17);
12153 48 }
12154
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12155 {
12156
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12157 new_return(17);
12158
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12159 new_return(17);
12160
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12161 new_return(17);
12162 48 }
12163
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12164 {
12165
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12166 new_return(17);
12167
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12168 new_return(17);
12169
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12170 new_return(17);
12171 48 }
12172
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12173 {
12174
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12175 new_return(18);
12176
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12177 new_return(18);
12178
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12179 new_return(18);
12180 48 }
12181
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12182 {
12183
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12184 new_return(19);
12185 48 }
12186
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12187 {
12188
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12189 new_return(20);
12190
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12191 new_return(20);
12192
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12193 new_return(20);
12194 36 }
12195
12196
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12197 {
12198 new_return(21);
12199 }
12200
12201
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12202 {
12203 new_return(21);
12204 }
12205
12206
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12207 {
12208 new_return(21);
12209 }
12210
12211
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12212 {
12213
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12214 new_return(22);
12215
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12216 new_return(22);
12217
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12218 new_return(22);
12219 48 }
12220
12221
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12222 {
12223
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12224 {
12225 new_return(23);
12226 }
12227
12228
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12229 {
12230 new_return(23);
12231 }
12232
12233
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12234 {
12235 new_return(23);
12236 }
12237 48 }
12238
12239
12240
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12241 {
12242
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12243 new_return(15);
12244 1752 }
12245 //}
12246
12247
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12248 {
12249 6 section_size=writesize;
12250 6 }
12251 12 }
12252
12253 //More data will come here
12254
12255
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12256 {
12257 char ebuf[80];
12258 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12259 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12260 }
12261
12262 6 new_return(0);
12263 }
12264
12265 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12266 {
12267 6 dword section_id=ID_SUBSCREEN;
12268 6 dword section_version=V_SUBSCREEN;
12269 6 dword section_cversion=CV_SUBSCREEN;
12270 6 dword section_size=0;
12271
12272 //section id
12273
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12274 {
12275 new_return(1);
12276 }
12277
12278 //section version info
12279
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12280 {
12281 new_return(2);
12282 }
12283
12284
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12285 {
12286 new_return(3);
12287 }
12288
12289
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12290 {
12291 12 fake_pack_writing=(writecycle==0);
12292
12293 //section size
12294
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12295 {
12296 new_return(4);
12297 }
12298
12299 12 writesize=0;
12300
12301 12 byte sz = subscreens_active.size();
12302
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12303 new_return(5);
12304
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12305 {
12306 66 int32_t ret = subscreens_active[i].write(f);
12307 66 fake_pack_writing=(writecycle==0);
12308
12309
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12310 new_return(ret);
12311 66 }
12312
12313 12 sz = subscreens_passive.size();
12314
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12315 new_return(5);
12316
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12317 {
12318 50 int32_t ret = subscreens_passive[i].write(f);
12319 50 fake_pack_writing=(writecycle==0);
12320
12321
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12322 new_return(ret);
12323 50 }
12324
12325 12 sz = subscreens_overlay.size();
12326
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12327 new_return(5);
12328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12329 {
12330 int32_t ret = subscreens_overlay[i].write(f);
12331 fake_pack_writing=(writecycle==0);
12332
12333 if(ret!=0)
12334 new_return(ret);
12335 }
12336
12337
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12338 {
12339 6 section_size=writesize;
12340 6 }
12341 12 }
12342
12343
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12344 {
12345 char ebuf[80];
12346 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12347 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12348 }
12349
12350 6 new_return(0);
12351 6 }
12352
12353 extern script_data *ffscripts[NUMSCRIPTFFC];
12354 extern script_data *itemscripts[NUMSCRIPTITEM];
12355 extern script_data *guyscripts[NUMSCRIPTGUYS];
12356 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12357 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12358 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12359 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12360 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12361 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12362 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12363 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12364 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12365 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12366
12367 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12368 {
12369 6 dword section_id = ID_FFSCRIPT;
12370 6 dword section_version = V_FFSCRIPT;
12371 6 dword section_cversion = CV_FFSCRIPT;
12372 6 dword section_size = 0;
12373 6 dword zasmmeta_version = METADATA_V;
12374 6 byte numscripts = 0;
12375 6 numscripts = numscripts; //to avoid unused variables warnings
12376
12377 //section id
12378
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12379 {
12380 new_return(1);
12381 }
12382
12383 //section version info
12384
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12385 {
12386 new_return(2);
12387 }
12388
12389
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12390 {
12391 new_return(3);
12392 }
12393
12394
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12395 {
12396 new_return(4);
12397 }
12398
12399
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12400 {
12401 12 fake_pack_writing=(writecycle==0);
12402
12403 //section size
12404
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12405 {
12406 new_return(5);
12407 }
12408
12409 12 writesize=0;
12410
12411
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12412 {
12413 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12414 6144 fake_pack_writing=(writecycle==0);
12415
12416
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12417 {
12418 new_return(ret);
12419 }
12420 6144 }
12421
12422
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12423 {
12424 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12425 3072 fake_pack_writing=(writecycle==0);
12426
12427
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12428 {
12429 new_return(ret);
12430 }
12431 3072 }
12432
12433
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12434 {
12435 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12436 3072 fake_pack_writing=(writecycle==0);
12437
12438
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12439 {
12440 new_return(ret);
12441 }
12442 3072 }
12443
12444
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12445
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12446 {
12447 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12448 3072 fake_pack_writing=(writecycle==0);
12449
12450
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12451 {
12452 new_return(ret);
12453 }
12454 3072 }
12455
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12456
12457
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12458 {
12459 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12460 3072 fake_pack_writing=(writecycle==0);
12461
12462
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12463 {
12464 new_return(ret);
12465 }
12466 3072 }
12467
12468
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12469 {
12470 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12471 96 fake_pack_writing=(writecycle==0);
12472
12473
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12474 {
12475 new_return(ret);
12476 }
12477 96 }
12478
12479
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12480 {
12481 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12482 60 fake_pack_writing=(writecycle==0);
12483
12484
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12485 {
12486 new_return(ret);
12487 }
12488 60 }
12489
12490
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12491 {
12492 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12493 3072 fake_pack_writing=(writecycle==0);
12494
12495
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12496 {
12497 new_return(ret);
12498 }
12499 3072 }
12500
12501
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12502 {
12503 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12504 3072 fake_pack_writing=(writecycle==0);
12505
12506
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12507 {
12508 new_return(ret);
12509 }
12510 3072 }
12511
12512
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12513 {
12514 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12515 3072 fake_pack_writing=(writecycle==0);
12516
12517
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12518 {
12519 new_return(ret);
12520 }
12521 3072 }
12522
12523
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12524 {
12525 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12526 3072 fake_pack_writing=(writecycle==0);
12527
12528
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12529 {
12530 new_return(ret);
12531 }
12532 3072 }
12533
12534
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12535 {
12536 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12537 6144 fake_pack_writing=(writecycle==0);
12538
12539
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12540 {
12541 new_return(ret);
12542 }
12543 6144 }
12544
12545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12546 {
12547 new_return(2000);
12548 }
12549
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12550 {
12551 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12552 6144 fake_pack_writing=(writecycle==0);
12553
12554
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12555 {
12556 new_return(ret);
12557 }
12558 6144 }
12559
12560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12561 {
12562 new_return(2001);
12563 }
12564
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12565 {
12566 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12567 3072 fake_pack_writing=(writecycle==0);
12568
12569
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12570 {
12571 new_return(ret);
12572 }
12573 3072 }
12574
12575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12576 {
12577 new_return(2001);
12578 }
12579
12580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12581 {
12582 new_return(2002);
12583 }
12584
12585 12 word numffcbindings=0;
12586
12587
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12588 {
12589
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12590 {
12591 200 numffcbindings++;
12592 200 }
12593 6132 }
12594
12595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12596 {
12597 new_return(2003);
12598 }
12599
12600
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12601 {
12602
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12603 {
12604
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12605 {
12606 new_return(2004);
12607 }
12608
12609
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12610 {
12611 new_return(2005);
12612 }
12613
12614
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12615 {
12616 new_return(2006);
12617 }
12618 200 }
12619 6132 }
12620
12621 12 word numglobalbindings=0;
12622
12623
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12624 {
12625
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12626 {
12627 24 numglobalbindings++;
12628 24 }
12629 96 }
12630
12631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12632 {
12633 new_return(2007);
12634 }
12635
12636
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12637 {
12638
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12639 {
12640
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12641 {
12642 new_return(2008);
12643 }
12644
12645
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12646 {
12647 new_return(2009);
12648 }
12649
12650
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12651 {
12652 new_return(2010);
12653 }
12654 24 }
12655 96 }
12656
12657 12 word numitembindings=0;
12658
12659
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12660 {
12661
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12662 {
12663 24 numitembindings++;
12664 24 }
12665 3060 }
12666
12667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12668 {
12669 new_return(2011);
12670 }
12671
12672
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12673 {
12674
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12675 {
12676
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12677 {
12678 new_return(2012);
12679 }
12680
12681
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12682 {
12683 new_return(2013);
12684 }
12685
12686
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12687 {
12688 new_return(2014);
12689 }
12690 24 }
12691 3060 }
12692
12693 //new script types
12694 //npc scripts
12695 12 word numnpcbindings=0;
12696
12697
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12698 {
12699
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12700 {
12701 numnpcbindings++;
12702 }
12703 3060 }
12704
12705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12706 {
12707 new_return(2015);
12708 }
12709
12710
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12711 {
12712
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12713 {
12714 if(!p_iputw(it->first,f))
12715 {
12716 new_return(2016);
12717 }
12718
12719 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12720 {
12721 new_return(2017);
12722 }
12723
12724 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12725 {
12726 new_return(2018);
12727 }
12728 }
12729 3060 }
12730
12731 //lweapon
12732
12733 12 word numlwpnbindings=0;
12734
12735
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12736 {
12737
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12738 {
12739 numlwpnbindings++;
12740 }
12741 3060 }
12742
12743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12744 {
12745 new_return(2019);
12746 }
12747
12748
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12749 {
12750
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12751 {
12752 if(!p_iputw(it->first,f))
12753 {
12754 new_return(2020);
12755 }
12756
12757 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12758 {
12759 new_return(2021);
12760 }
12761
12762 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12763 {
12764 new_return(2022);
12765 }
12766 }
12767 3060 }
12768
12769 //////
12770
12771 //eweapon
12772
12773
12774 12 word numewpnbindings=0;
12775
12776
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12777 {
12778
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12779 {
12780 numewpnbindings++;
12781 }
12782 3060 }
12783
12784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12785 {
12786 new_return(2023);
12787 }
12788
12789
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12790 {
12791
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12792 {
12793 if(!p_iputw(it->first,f))
12794 {
12795 new_return(2024);
12796 }
12797
12798 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12799 {
12800 new_return(2025);
12801 }
12802
12803 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12804 {
12805 new_return(2026);
12806 }
12807 }
12808 3060 }
12809
12810 //player scripts
12811 12 word numherobindings=0;
12812
12813
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12814 {
12815
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12816 {
12817 2 numherobindings++;
12818 2 }
12819 48 }
12820
12821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12822 {
12823 new_return(2027);
12824 }
12825
12826
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12827 {
12828
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12829 {
12830
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12831 {
12832 new_return(2028);
12833 }
12834
12835
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12836 {
12837 new_return(2029);
12838 }
12839
12840
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12841 {
12842 new_return(2030);
12843 }
12844 2 }
12845 48 }
12846
12847 //dmap scripts
12848 12 word numdmapbindings=0;
12849
12850
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12851 {
12852
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12853 {
12854 4 numdmapbindings++;
12855 4 }
12856 3060 }
12857
12858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12859 {
12860 new_return(2031);
12861 }
12862
12863
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12864 {
12865
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12866 {
12867
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12868 {
12869 new_return(2032);
12870 }
12871
12872
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12873 {
12874 new_return(2033);
12875 }
12876
12877
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12878 {
12879 new_return(2034);
12880 }
12881 4 }
12882 3060 }
12883
12884 //screen scripts
12885 12 word numscreenbindings=0;
12886
12887
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12888 {
12889
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12890 {
12891 16 numscreenbindings++;
12892 16 }
12893 3060 }
12894
12895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12896 {
12897 new_return(2035);
12898 }
12899
12900
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12901 {
12902
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12903 {
12904
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12905 {
12906 new_return(2036);
12907 }
12908
12909
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12910 {
12911 new_return(2037);
12912 }
12913
12914
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12915 {
12916 new_return(2038);
12917 }
12918 16 }
12919 3060 }
12920 //item sprite scripts
12921 12 word numitemspritebindings=0;
12922
12923
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12924 {
12925
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12926 {
12927 numitemspritebindings++;
12928 }
12929 3060 }
12930
12931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12932 {
12933 new_return(2039);
12934 }
12935
12936
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12937 {
12938
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12939 {
12940 if(!p_iputw(it->first,f))
12941 {
12942 new_return(2040);
12943 }
12944
12945 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12946 {
12947 new_return(2041);
12948 }
12949
12950 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12951 {
12952 new_return(2042);
12953 }
12954 }
12955 3060 }
12956
12957 //combo scripts
12958 12 word numcombobindings=0;
12959
12960
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12961 {
12962
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12963 {
12964 numcombobindings++;
12965 }
12966 6132 }
12967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12968 {
12969 new_return(2043);
12970 }
12971
12972
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12973 {
12974
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12975 {
12976 if(!p_iputw(it->first,f))
12977 {
12978 new_return(2044);
12979 }
12980
12981 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12982 {
12983 new_return(2045);
12984 }
12985
12986 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12987 {
12988 new_return(2046);
12989 }
12990 }
12991 6132 }
12992 //subscreen scripts
12993 12 word numgenericbindings=0;
12994
12995
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12996 {
12997
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12998 {
12999 numgenericbindings++;
13000 }
13001 6132 }
13002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
13003 {
13004 new_return(2043);
13005 }
13006
13007
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13008 {
13009
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
13010 {
13011 if(!p_iputw(it->first,f))
13012 {
13013 new_return(2044);
13014 }
13015
13016 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13017 {
13018 new_return(2045);
13019 }
13020
13021 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13022 {
13023 new_return(2046);
13024 }
13025 }
13026 6132 }
13027
13028 //generic scripts
13029 12 word numsubscreenbindings=0;
13030
13031
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13032 {
13033
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13034 {
13035 numsubscreenbindings++;
13036 }
13037 3060 }
13038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
13039 {
13040 new_return(2047);
13041 }
13042
13043
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13044 {
13045
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13046 {
13047 if(!p_iputw(it->first,f))
13048 {
13049 new_return(2048);
13050 }
13051
13052 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13053 {
13054 new_return(2049);
13055 }
13056
13057 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13058 {
13059 new_return(2050);
13060 }
13061 }
13062 3060 }
13063
13064
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13065 {
13066 6 section_size=writesize;
13067 6 }
13068 12 }
13069
13070
13071
13072
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13073 {
13074 char ebuf[80];
13075 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13076 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13077 }
13078
13079 6 new_return(0);
13080 //return 0; //this is just here to stomp the compiler from whining.
13081 //the irony is that it causes an "unreachable code" warning.
13082 6 }
13083
13084 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
13085 {
13086 //these are here to bypass compiler warnings about unused arguments
13087 46236 Header=Header;
13088 46236 i=i;
13089
13090
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
13091
13092
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
13093 {
13094 new_return(6);
13095 }
13096
13097 //Metadata
13098 46236 zasm_meta const& tmeta = (*script)->meta;
13099
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
13100 {
13101 new_return(7);
13102 }
13103
13104
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
13105 {
13106 new_return(8);
13107 }
13108
13109
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
13110 {
13111 new_return(9);
13112 }
13113
13114
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13115 {
13116 new_return(10);
13117 }
13118
13119
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13120 {
13121
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13122 new_return(11);
13123 369888 }
13124
13125
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13126 {
13127
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13128 {
13129 new_return(12);
13130 }
13131 369888 }
13132
13133
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13134 {
13135 new_return(13);
13136 }
13137
13138
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13139 {
13140 new_return(14);
13141 }
13142
13143
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13144 {
13145 new_return(15);
13146 }
13147
13148
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13149 {
13150 new_return(16);
13151 }
13152
13153
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13154 {
13155 new_return(17);
13156 }
13157
13158
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13159 new_return(18);
13160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13161 new_return(19);
13162
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13163 {
13164
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13165 new_return(27);
13166
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13167 new_return(28);
13168 462360 }
13169
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13170 {
13171
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13172 new_return(29);
13173
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13174 new_return(30);
13175 369888 }
13176
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13177 {
13178
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13179 new_return(31);
13180
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13181 new_return(32);
13182 369888 }
13183
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13184 {
13185
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13186 new_return(33);
13187
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13188 new_return(34);
13189 739776 }
13190
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13191 {
13192
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13193 new_return(35);
13194
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13195 new_return(36);
13196 369888 }
13197
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13198 {
13199
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13200 new_return(37);
13201 369888 }
13202
13203
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626442 times.
663184 for(int32_t j=0; j<num_commands; j++)
13204 {
13205 626442 auto& zas = (*script)->zasm_script->zasm[j];
13206
1/2
✓ Branch 0 taken 626442 times.
✗ Branch 1 not taken.
626442 if(!p_iputw(zas.command,f))
13207 {
13208 new_return(20);
13209 }
13210
13211
2/2
✓ Branch 0 taken 616948 times.
✓ Branch 1 taken 9494 times.
626442 if(zas.command==0xFFFF)
13212 {
13213 9494 break;
13214 }
13215 else
13216 {
13217
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg1,f))
13218 {
13219 new_return(21);
13220 }
13221
13222
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg2,f))
13223 {
13224 new_return(22);
13225 }
13226
13227
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg3,f))
13228 {
13229 new_return(23);
13230 }
13231
13232 616948 uint32_t sz = 0;
13233
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614178 times.
616948 if(zas.strptr)
13234 2770 sz = zas.strptr->size();
13235
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13236 {
13237 new_return(23);
13238 }
13239
2/2
✓ Branch 0 taken 614178 times.
✓ Branch 1 taken 2770 times.
616948 if(sz)
13240 {
13241 2770 auto& str = *zas.strptr;
13242
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13243 {
13244
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13245 {
13246 new_return(24);
13247 }
13248 222648 }
13249 2770 }
13250 616948 sz = 0;
13251
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(zas.vecptr)
13252 114 sz = zas.vecptr->size();
13253
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13254 {
13255 new_return(25);
13256 }
13257
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(sz) //vector found
13258 {
13259 114 auto& vec = *zas.vecptr;
13260
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13261 {
13262
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13263 {
13264 new_return(26);
13265 }
13266 850 }
13267 114 }
13268 }
13269 616948 }
13270
13271 46236 new_return(0);
13272 }
13273
13274 extern SAMPLE customsfxdata[WAV_COUNT];
13275 extern uint8_t customsfxflag[WAV_COUNT>>3];
13276
13277 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13278 {
13279 //these are here to bypass compiler warnings about unused arguments
13280 6 Header=Header;
13281
13282 6 dword section_id=ID_SFX;
13283 6 dword section_version=V_SFX;
13284 6 dword section_cversion=CV_SFX;
13285 6 dword section_size=0;
13286
13287 //section id
13288
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13289 {
13290 new_return(1);
13291 }
13292
13293 //section version info
13294
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13295 {
13296 new_return(2);
13297 }
13298
13299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13300 {
13301 new_return(3);
13302 }
13303
13304
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13305 {
13306 12 fake_pack_writing=(writecycle==0);
13307
13308 //section size
13309
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13310 {
13311 new_return(4);
13312 }
13313
13314 12 writesize=0;
13315
13316
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13317 {
13318
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13319 {
13320 new_return(5);
13321 }
13322 384 }
13323
13324
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13325 {
13326
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13327 2240 continue;
13328
13329
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13330 {
13331 new_return(5);
13332 }
13333 820 }
13334
13335
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13336 {
13337
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13338 2240 continue;
13339
13340
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13341 {
13342 new_return(5);
13343 }
13344
13345
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13346 {
13347 new_return(6);
13348 }
13349
13350
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13351 {
13352 new_return(7);
13353 }
13354
13355
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13356 {
13357 new_return(8);
13358 }
13359
13360
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13361 {
13362 new_return(9);
13363 }
13364
13365
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13366 {
13367 new_return(10);
13368 }
13369
13370
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13371 {
13372 new_return(11);
13373 }
13374
13375
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13376 {
13377 new_return(12);
13378 }
13379
13380 //de-endianfy the data
13381 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13382
13383
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13384 {
13385
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13386 {
13387 new_return(13);
13388 }
13389 18594894 }
13390 820 }
13391
13392
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13393 {
13394 6 section_size=writesize;
13395 6 }
13396 12 }
13397
13398
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13399 {
13400 char ebuf[80];
13401 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13402 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13403 }
13404
13405 6 new_return(0);
13406 }
13407
13408 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13409 {
13410 6 dword section_id=ID_INITDATA;
13411 6 dword section_version=V_INITDATA;
13412 6 dword section_cversion=CV_INITDATA;
13413 6 dword section_size = 0;
13414
13415 6 zinit.last_map=Map.getCurrMap();
13416 6 zinit.last_screen=Map.getCurrScr();
13417 6 zinit.normalize();
13418
13419 //section id
13420
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13421 {
13422 new_return(1);
13423 }
13424
13425 //section version info
13426
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13427 {
13428 new_return(2);
13429 }
13430
13431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13432 {
13433 new_return(3);
13434 }
13435
13436 //TODO
13437
13438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13439 {
13440 12 fake_pack_writing=(writecycle==0);
13441
13442 //section size
13443
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13444 new_return(4);
13445
13446 12 writesize=0;
13447
13448
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13449
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13450 new_return(5);
13451
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13452 {
13453
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13454 new_return(6);
13455
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13456 new_return(7);
13457
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13458 new_return(8);
13459
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13460 new_return(9);
13461 768 }
13462
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13463 new_return(10);
13464
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13465 new_return(11);
13466
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13467
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13468 new_return(12);
13469
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13470
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13471 new_return(13);
13472
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13473 new_return(14);
13474
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13475 new_return(15);
13476
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13477 new_return(16);
13478
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13479 new_return(17);
13480
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13481 new_return(18);
13482
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13483 new_return(19);
13484
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13485 new_return(20);
13486
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13487 new_return(21);
13488
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13489 new_return(22);
13490
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13491 new_return(23);
13492
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13493 new_return(24);
13494
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13495 new_return(25);
13496
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13497 new_return(26);
13498
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13499 new_return(27);
13500
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13501 new_return(28);
13502
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13503 new_return(29);
13504
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13505 new_return(30);
13506
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13507 new_return(31);
13508
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13509 new_return(32);
13510
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13511 new_return(33);
13512
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13513 new_return(34);
13514
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13515 new_return(35);
13516
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13517 new_return(36);
13518
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13519 new_return(37);
13520
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13521 new_return(38);
13522
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13523 new_return(39);
13524
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13525 new_return(40);
13526
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13527 new_return(41);
13528
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13529 new_return(42);
13530
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13531 new_return(43);
13532
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13533 new_return(44);
13534
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13535 new_return(45);
13536
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13537 new_return(46);
13538
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13539 new_return(47);
13540
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13541 new_return(48);
13542
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13543 new_return(49);
13544
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13545 new_return(50);
13546
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13547 new_return(51);
13548
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13549 new_return(52);
13550
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13551 new_return(53);
13552
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13553 new_return(54);
13554
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13555 new_return(55);
13556
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13557 new_return(56);
13558
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13559 new_return(57);
13560
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13561 new_return(58);
13562
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13563 new_return(59);
13564
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13565 new_return(60);
13566
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13567 new_return(61);
13568
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13569 new_return(62);
13570
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13571 new_return(63);
13572
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13573 new_return(64);
13574
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13575 new_return(65);
13576
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13577 new_return(66);
13578
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13579 new_return(67);
13580
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13581 new_return(68);
13582
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13583 new_return(69);
13584
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13585 new_return(70);
13586
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13587 new_return(71);
13588
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13589 new_return(72);
13590
13591
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13592 {
13593 6 section_size=writesize;
13594 6 }
13595 12 }
13596
13597
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13598 {
13599 char ebuf[80];
13600 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13601 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13602 }
13603
13604 6 new_return(0);
13605 }
13606
13607 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13608 {
13609 //these are here to bypass compiler warnings about unused arguments
13610 6 Header=Header;
13611
13612 6 dword section_id=ID_ITEMDROPSETS;
13613 6 dword section_version=V_ITEMDROPSETS;
13614 6 dword section_cversion=CV_ITEMDROPSETS;
13615 // dword section_size=0;
13616 6 dword section_size = 0;
13617 6 word num_item_drop_sets=count_item_drop_sets();
13618
13619 //section id
13620
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13621 {
13622 new_return(1);
13623 }
13624
13625 //section version info
13626
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13627 {
13628 new_return(2);
13629 }
13630
13631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13632 {
13633 new_return(3);
13634 }
13635
13636
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13637 {
13638 12 fake_pack_writing=(writecycle==0);
13639
13640 //section size
13641
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13642 {
13643 new_return(4);
13644 }
13645
13646 12 writesize=0;
13647
13648 //finally... section data
13649
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13650 {
13651 new_return(5);
13652 }
13653
13654
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13655 {
13656
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13657 {
13658 new_return(6);
13659 }
13660
13661
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13662 {
13663
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13664 {
13665 new_return(7);
13666 }
13667 1580 }
13668
13669
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13670 {
13671
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13672 {
13673 new_return(8);
13674 }
13675 1738 }
13676 158 }
13677
13678
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13679 {
13680 6 section_size=writesize;
13681 6 }
13682 12 }
13683
13684
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13685 {
13686 char ebuf[80];
13687 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13688 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13689 }
13690
13691 6 new_return(0);
13692 }
13693
13694 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13695 {
13696 6 dword section_id=ID_FAVORITES;
13697 6 dword section_version=V_FAVORITES;
13698 6 dword section_cversion=CV_FAVORITES;
13699 6 dword section_size = 0;
13700
13701 //section id
13702
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13703 {
13704 new_return(1);
13705 }
13706
13707 //section version info
13708
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13709 {
13710 new_return(2);
13711 }
13712
13713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13714 {
13715 new_return(3);
13716 }
13717
13718
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13719 {
13720 12 fake_pack_writing=(writecycle==0);
13721
13722 //section size
13723
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13724 new_return(4);
13725
13726 12 writesize=0;
13727
13728
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13729 new_return(16);
13730
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13731 new_return(17);
13732
13733 12 word favcmb_cnt = 0;
13734
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13735
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13736 {
13737 8 favcmb_cnt = q+1;
13738 8 break;
13739 }
13740
13741
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13742 new_return(5);
13743
13744
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13745 {
13746
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13747 new_return(6);
13748
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13749 new_return(7);
13750 210 }
13751
13752
13753 12 word max_combo_cols = MAX_COMBO_COLS;
13754
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13755 new_return(9);
13756
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13757 {
13758
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13759 new_return(10);
13760
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13761 new_return(11);
13762
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13763 new_return(12);
13764 48 }
13765 12 word max_mappages = MAX_MAPPAGE_BTNS;
13766
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13767 new_return(13);
13768
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13769 {
13770
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13771 new_return(14);
13772
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13773 new_return(15);
13774 108 }
13775
13776
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13777 {
13778 6 section_size=writesize;
13779 6 }
13780 12 }
13781
13782
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13783 {
13784 char ebuf[80];
13785 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13786 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13787 }
13788
13789 6 new_return(0);
13790 }
13791
13792 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13793 {
13794
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13795 6 reset_combo_animations();
13796 6 reset_combo_animations2();
13797 6 strcpy(header.id_str,QH_NEWIDSTR);
13798 6 header.zelda_version = ZELDA_VERSION;
13799 6 header.internal = INTERNAL_VERSION;
13800 // header.str_count = msg_count;
13801 // header.data_flags[ZQ_TILES] = usetiles;
13802 6 header.data_flags[ZQ_TILES] = true;
13803 6 header.data_flags[ZQ_CHEATS2] = 1;
13804 6 header.build=VERSION_BUILD;
13805
13806
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13807 {
13808 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13809 1512 }
13810
13811 char zinfofilename[2048];
13812 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13813
13814 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13815 6 box_out("Saving Quest...");
13816 6 box_eol();
13817 6 box_eol();
13818
13819
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13820
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13821
13822
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13823 return 1;
13824
13825
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13826
13827
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13828 return 2;
13829
13830
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13831
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13832
13833
13834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13835 {
13836 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13837
13838 box_out("Writing ZInfo...");
13839 if(inf)
13840 {
13841 if(writezinfo(inf,ZI)!=0)
13842 return 2;
13843
13844 pack_fclose(inf);
13845 box_out("okay.");
13846 }
13847 else box_out(" ...file failure");
13848 box_eol();
13849 }
13850 else
13851 {
13852
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13853
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13854 return 2;
13855
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13856
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13857 }
13858
13859
13860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13861
13862
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13863 return 3;
13864
13865
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13866
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13867
13868
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13869
13870
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13871 return 4;
13872
13873
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13874
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13875
13876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13877
13878
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13879 return 5;
13880
13881
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13882
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13883
13884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13885
13886
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13887 return 6;
13888
13889
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13890
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13891
13892
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13893
13894
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13895 return 7;
13896
13897
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13898
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13899
13900
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13901
13902
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13903 return 8;
13904
13905
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13906
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13907
13908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13909
13910
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13911 return 9;
13912
13913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13914
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13915
13916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13917
13918
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13919 return 10;
13920
13921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13923
13924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13925
13926
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13927 return 11;
13928
13929
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13930
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13931
13932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13933
13934
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13935 return 12;
13936
13937
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13938
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13939
13940
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13941
13942
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13943 return 13;
13944
13945
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13946
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13947
13948
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13949
13950
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13951 return 14;
13952
13953
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13954
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13955
13956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13957
13958
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13959 return 15;
13960
13961
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13962
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13963
13964
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13965
13966
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13967 return 16;
13968
13969
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13970
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13971
13972
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13973
13974
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13975 return 17;
13976
13977
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13978
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13979
13980
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13981
13982
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13983 return 18;
13984
13985
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13986
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13987
13988
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13989
13990
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13991 return 19;
13992
13993
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13994
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13995
13996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13997
13998
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13999 return 20;
14000
14001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14002
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14003
14004
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
14005
14006
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
14007 return 21;
14008
14009
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14010
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14011
14012
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
14013
14014
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
14015 return 22;
14016
14017
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14018
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14019
14020
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
14021
14022
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
14023 return 23;
14024
14025
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14026
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14027
14028
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
14029
14030
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
14031 return 24;
14032
14033
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14034
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14035
14036
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
14037
14038
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
14039 return 25;
14040
14041
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14042
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14043
14044
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
14045
14046
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
14047 return 26;
14048
14049
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14050
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14051
14052
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
14053
14054
14055
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
14056 {
14057 char const* kfname = filename;
14058 char keyfilename[2048]={0};
14059 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14060
14061 char temp_pw[QSTPWD_LEN] = {0};
14062 uint ind = 0;
14063 for(char const* ext : {"key","zpwd","zcheat"})
14064 {
14065 replace_extension(keyfilename, kfname, ext, 2047);
14066 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14067 char msg[80] = {0};
14068 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14069 msg[78]=13;
14070 msg[79]=10;
14071 pfwrite(msg, 80, fp);
14072 p_iputw(header.zelda_version,fp);
14073 p_putc(header.build,fp);
14074 char const* pwd = header.password;
14075 if(ind == 2) //.zcheat, hashed pwd
14076 {
14077 char hashmap = 'Z';
14078 hashmap += 'Q';
14079 hashmap += 'U';
14080 hashmap += 'E';
14081 hashmap += 'S';
14082 hashmap += 'T';
14083 for ( int q = 0; q < QSTPWD_LEN; ++q )
14084 {
14085 temp_pw[q] = header.password[q];
14086 temp_pw[q] += hashmap;
14087 }
14088 pwd = temp_pw;
14089 }
14090 pfwrite(pwd, strlen(pwd), fp);
14091 pack_fclose(fp);
14092 ++ind;
14093 }
14094 }
14095
14096 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14097 6 std::error_code ec;
14098
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
14099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
14100 {
14101 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14102 return ec.value();
14103 }
14104
14105
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14106
14107 #ifdef __EMSCRIPTEN__
14108 em_sync_fs();
14109 #endif
14110
14111 6 return 0;
14112 6 }
14113
14114 // #ifdef _WIN32
14115 // static std::time_t to_time_t(FILETIME const& ft) {
14116 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14117 // t -= 116444736000000000ull;
14118 // t /= 10000000u;
14119 // return static_cast<std::time_t>(t);
14120 // }
14121 // #else
14122 // #endif
14123 template<typename TP>
14124 4 static std::time_t to_time_t(TP tp) {
14125 using namespace std::chrono;
14126 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14127 4 return system_clock::to_time_t(sctp);
14128 }
14129
14130 4 std::string get_time_last_modified_string(std::string path)
14131 {
14132
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14133 // TODO: C++20 but not supported yet.
14134 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14135 4 std::time_t tt = to_time_t(write_time);
14136 4 std::tm *gmt = std::gmtime(&tt);
14137 4 std::stringstream buffer;
14138
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14139
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14140 4 return formattedFileTime;
14141
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14142
14143 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14144 {
14145 // Always backup quest if it was last saved in a different version of the editor,
14146 // or if this a new file and is overwritting another qst file.
14147
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14148 {
14149 4 std::string backup_name;
14150
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14151
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14152 {
14153
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14154 4 }
14155 else
14156 {
14157 backup_name = fmt::format("{}", last_mod);
14158 }
14159
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14160
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14161
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14162 {
14163
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14164
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14165 {
14166
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14167 4 }
14168 else
14169 {
14170 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14171 }
14172 4 }
14173 4 }
14174
14175 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14176 6 fake_pack_writing = false;
14177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14178 {
14179 box_out("-- Error saving quest file! --");
14180 box_end(true);
14181 }
14182 6 else box_end(false);
14183 6 return ret;
14184 }
14185
14186 6 int32_t save_quest(const char *filename, bool timed_save)
14187 {
14188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14189
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14190 char ext1[5];
14191 6 ext1[0]=0;
14192
14193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14194 {
14195 sprintf(ext1, "qt");
14196 }
14197 else
14198 {
14199 6 sprintf(ext1, "qb");
14200 }
14201
14202
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14203 {
14204 char backupname[2048];
14205 char backupname2[2048];
14206 char ext[12];
14207
14208 for(int32_t i=retention-1; i>0; --i)
14209 {
14210 sprintf(ext, "%s%d", ext1, i-1);
14211 replace_extension(backupname, filepath, ext, 2047);
14212
14213 if(exists(backupname))
14214 {
14215 sprintf(ext, "%s%d", ext1, i);
14216 replace_extension(backupname2, filepath, ext, 2047);
14217
14218 if(exists(backupname2))
14219 {
14220 remove(backupname2);
14221 }
14222
14223 rename(backupname, backupname2);
14224 }
14225 }
14226
14227 //don't do this if we're not saving to the same name -DD
14228 if(!timed_save && !strcmp(filepath, filename))
14229 {
14230 sprintf(ext, "%s%d", ext1, 0);
14231 replace_extension(backupname, filepath, ext, 2047);
14232 rename(filepath, backupname);
14233 }
14234 }
14235
14236 int32_t ret;
14237 6 ret = save_unencoded_quest(filename, compress, filename);
14238
14239 6 return ret;
14240 }
14241
14242 6 void center_zq_class_dialogs()
14243 {
14244 6 jwin_center_dialog(pwd_dlg);
14245 6 }
14246
14247 void zmap::prv_secrets(bool high16only)
14248 {
14249 mapscr *s = &prvscr;
14250 mapscr *t = prvlayers;
14251 int32_t ft=0;
14252
14253 for(int32_t i=0; i<176; i++)
14254 {
14255 bool putit;
14256
14257 if(!high16only)
14258 {
14259 for(int32_t j=-1; j<6; j++)
14260 {
14261 int32_t newflag = -1;
14262
14263 for(int32_t iter=0; iter<2; ++iter)
14264 {
14265 putit=true;
14266
14267 if(!t[j].valid)
14268 continue;
14269
14270 int32_t checkflag=combobuf[t[j].data[i]].flag;
14271
14272 if(iter==1)
14273 {
14274 checkflag=t[j].sflag[i];
14275 }
14276
14277 switch(checkflag)
14278 {
14279 case mfANYFIRE:
14280 ft=sBCANDLE;
14281 break;
14282
14283 case mfSTRONGFIRE:
14284 ft=sRCANDLE;
14285 break;
14286
14287 case mfMAGICFIRE:
14288 ft=sWANDFIRE;
14289 break;
14290
14291 case mfDIVINEFIRE:
14292 ft=sDIVINEFIRE;
14293 break;
14294
14295 case mfARROW:
14296 ft=sARROW;
14297 break;
14298
14299 case mfSARROW:
14300 ft=sSARROW;
14301 break;
14302
14303 case mfGARROW:
14304 ft=sGARROW;
14305 break;
14306
14307 case mfSBOMB:
14308 ft=sSBOMB;
14309 break;
14310
14311 case mfBOMB:
14312 ft=sBOMB;
14313 break;
14314
14315 case mfBRANG:
14316 ft=sBRANG;
14317 break;
14318
14319 case mfMBRANG:
14320 ft=sMBRANG;
14321 break;
14322
14323 case mfFBRANG:
14324 ft=sFBRANG;
14325 break;
14326
14327 case mfWANDMAGIC:
14328 ft=sWANDMAGIC;
14329 break;
14330
14331 case mfREFMAGIC:
14332 ft=sREFMAGIC;
14333 break;
14334
14335 case mfREFFIREBALL:
14336 ft=sREFFIREBALL;
14337 break;
14338
14339 case mfSWORD:
14340 ft=sSWORD;
14341 break;
14342
14343 case mfWSWORD:
14344 ft=sWSWORD;
14345 break;
14346
14347 case mfMSWORD:
14348 ft=sMSWORD;
14349 break;
14350
14351 case mfXSWORD:
14352 ft=sXSWORD;
14353 break;
14354
14355 case mfSWORDBEAM:
14356 ft=sSWORDBEAM;
14357 break;
14358
14359 case mfWSWORDBEAM:
14360 ft=sWSWORDBEAM;
14361 break;
14362
14363 case mfMSWORDBEAM:
14364 ft=sMSWORDBEAM;
14365 break;
14366
14367 case mfXSWORDBEAM:
14368 ft=sXSWORDBEAM;
14369 break;
14370
14371 case mfHOOKSHOT:
14372 ft=sHOOKSHOT;
14373 break;
14374
14375 case mfWAND:
14376 ft=sWAND;
14377 break;
14378
14379 case mfHAMMER:
14380 ft=sHAMMER;
14381 break;
14382
14383 case mfSTRIKE:
14384 ft=sSTRIKE;
14385 break;
14386
14387 default:
14388 putit = false;
14389 break;
14390 }
14391
14392 if(putit)
14393 {
14394 if(j==-1)
14395 {
14396 s->data[i] = s->secretcombo[ft];
14397 s->cset[i] = s->secretcset[ft];
14398 newflag = s->secretflag[ft];
14399 }
14400 else
14401 {
14402 t[j].data[i] = t[j].secretcombo[ft];
14403 t[j].cset[i] = t[j].secretcset[ft];
14404 newflag = t[j].secretflag[ft];
14405 }
14406 }
14407 }
14408
14409 if(newflag >-1)
14410 {
14411 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14412 }
14413 }
14414 }
14415
14416 //if(true)
14417 //{
14418 int32_t newflag = -1;
14419
14420 for(int32_t iter=0; iter<2; ++iter)
14421 {
14422 int32_t checkflag=combobuf[s->data[i]].flag;
14423
14424 if(iter==1)
14425 {
14426 checkflag=s->sflag[i];
14427 }
14428
14429 if((checkflag > 15)&&(checkflag < 32))
14430 {
14431 s->data[i] = s->secretcombo[(checkflag)-16+4];
14432 s->cset[i] = s->secretcset[(checkflag)-16+4];
14433 newflag = s->secretflag[(checkflag)-16+4];
14434 // putit = true;
14435 }
14436 }
14437
14438 if(newflag >-1) s->sflag[i] = newflag;
14439
14440 for(int32_t j=0; j<6; j++)
14441 {
14442 if(!t[j].valid) continue;
14443
14444 int32_t newflag2 = -1;
14445
14446 for(int32_t iter=0; iter<2; ++iter)
14447 {
14448 int32_t checkflag=combobuf[t[j].data[i]].flag;
14449
14450 if(iter==1)
14451 {
14452 checkflag=t[j].sflag[i];
14453 }
14454
14455 if((checkflag > 15)&&(checkflag < 32))
14456 {
14457 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14458 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14459 newflag2 = t[j].secretflag[(checkflag)-16+4];
14460 }
14461 }
14462
14463 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14464 }
14465 }
14466
14467 //FFCs
14468 word c = s->numFFC();
14469 for(word i=0; i<c; ++i)
14470 {
14471 bool putit;
14472
14473 if(!high16only)
14474 {
14475 for(int32_t iter=0; iter<1; ++iter)
14476 {
14477 putit=true;
14478 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14479
14480 if(iter==1)
14481 {
14482 checkflag=s->sflag[i];
14483 }
14484
14485 switch(checkflag)
14486 {
14487 case mfANYFIRE:
14488 ft=sBCANDLE;
14489 break;
14490
14491 case mfSTRONGFIRE:
14492 ft=sRCANDLE;
14493 break;
14494
14495 case mfMAGICFIRE:
14496 ft=sWANDFIRE;
14497 break;
14498
14499 case mfDIVINEFIRE:
14500 ft=sDIVINEFIRE;
14501 break;
14502
14503 case mfARROW:
14504 ft=sARROW;
14505 break;
14506
14507 case mfSARROW:
14508 ft=sSARROW;
14509 break;
14510
14511 case mfGARROW:
14512 ft=sGARROW;
14513 break;
14514
14515 case mfSBOMB:
14516 ft=sSBOMB;
14517 break;
14518
14519 case mfBOMB:
14520 ft=sBOMB;
14521 break;
14522
14523 case mfBRANG:
14524 ft=sBRANG;
14525 break;
14526
14527 case mfMBRANG:
14528 ft=sMBRANG;
14529 break;
14530
14531 case mfFBRANG:
14532 ft=sFBRANG;
14533 break;
14534
14535 case mfWANDMAGIC:
14536 ft=sWANDMAGIC;
14537 break;
14538
14539 case mfREFMAGIC:
14540 ft=sREFMAGIC;
14541 break;
14542
14543 case mfREFFIREBALL:
14544 ft=sREFFIREBALL;
14545 break;
14546
14547 case mfSWORD:
14548 ft=sSWORD;
14549 break;
14550
14551 case mfWSWORD:
14552 ft=sWSWORD;
14553 break;
14554
14555 case mfMSWORD:
14556 ft=sMSWORD;
14557 break;
14558
14559 case mfXSWORD:
14560 ft=sXSWORD;
14561 break;
14562
14563 case mfSWORDBEAM:
14564 ft=sSWORDBEAM;
14565 break;
14566
14567 case mfWSWORDBEAM:
14568 ft=sWSWORDBEAM;
14569 break;
14570
14571 case mfMSWORDBEAM:
14572 ft=sMSWORDBEAM;
14573 break;
14574
14575 case mfXSWORDBEAM:
14576 ft=sXSWORDBEAM;
14577 break;
14578
14579 case mfHOOKSHOT:
14580 ft=sHOOKSHOT;
14581 break;
14582
14583 case mfWAND:
14584 ft=sWAND;
14585 break;
14586
14587 case mfHAMMER:
14588 ft=sHAMMER;
14589 break;
14590
14591 case mfSTRIKE:
14592 ft=sSTRIKE;
14593 break;
14594
14595 default:
14596 putit = false;
14597 break;
14598 }
14599
14600 if(putit)
14601 {
14602 s->ffcs[i].data = s->secretcombo[ft];
14603 s->ffcs[i].cset = s->secretcset[ft];
14604 }
14605 }
14606 }
14607
14608 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14609 {
14610 for(int32_t iter=0; iter<1; ++iter)
14611 {
14612 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14613
14614 if(iter==1)
14615 {
14616 // FFCs can't have flags! Yet...
14617 }
14618
14619 if((checkflag > 15)&&(checkflag < 32))
14620 {
14621 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14622 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14623 }
14624 }
14625 }
14626 }
14627 }
14628